Skip to content

Commit fc522d6

Browse files
mvd-owsdstebila
authored andcommitted
Embed SIDH IQC REFERENCE parameters (open-quantum-safe#180)
* Embed SIDH IQC REFERENCE parameters * Adjust code formatting * Add default selection of parameters
1 parent 40ffb4e commit fc522d6

13 files changed

+148
-74
lines changed

src/kex/kex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ OQS_KEX *OQS_KEX_new(OQS_RAND *rand, enum OQS_KEX_alg_name alg_name, const uint8
8585

8686
case OQS_KEX_alg_sidh_iqc_ref:
8787
#ifdef ENABLE_SIDH_IQC_REF
88-
return OQS_KEX_sidh_iqc_ref_new(rand);
88+
return OQS_KEX_sidh_iqc_ref_new(rand, named_parameters);
8989
#else
9090
assert(0);
9191
#endif

src/kex/test_kex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct kex_testcase kex_testcases[] = {
5151
{OQS_KEX_alg_sidh_cln16_compressed, NULL, 0, "compressedp751", "sidh_cln16_compressed", 0, 10},
5252
#endif
5353
#ifdef ENABLE_SIDH_IQC_REF
54-
{OQS_KEX_alg_sidh_iqc_ref, NULL, 0, NULL, "sidh_iqc_ref", 0, 10},
54+
{OQS_KEX_alg_sidh_iqc_ref, NULL, 0, "params771", "sidh_iqc_ref", 0, 10},
5555
#endif
5656
};
5757

src/kex_sidh_iqc_ref/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = foreign
22
noinst_LTLIBRARIES = libsidhiqc.la
33

44

5-
libsidhiqc_la_SOURCES = kex_sidh_iqc_ref.c sidh_elliptic_curve.c sidh_elliptic_curve_dlp.c sidh_isogeny.c
5+
libsidhiqc_la_SOURCES = kex_sidh_iqc_ref_params.c kex_sidh_iqc_ref.c sidh_elliptic_curve.c sidh_elliptic_curve_dlp.c sidh_isogeny.c
66
libsidhiqc_la_SOURCES += sidh_private_key.c sidh_public_key.c sidh_public_key_encryption.c sidh_public_key_validation.c
77
libsidhiqc_la_SOURCES += sidh_public_param.c sidh_quadratic_ext.c sidh_shared_key.c sidh_util.c
88
libsidhiqc_la_CPPFLAGS = -I../../include -I.-fPIC

src/kex_sidh_iqc_ref/kex_sidh_iqc_ref.c

+31-7
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,36 @@
1414
#include "sidh_public_key.h"
1515
#include "sidh_shared_key.h"
1616
#include "kex_sidh_iqc_ref.h"
17+
#include "kex_sidh_iqc_ref_params.h"
1718

18-
OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand) {
19+
OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand, const char *named_parameters) {
20+
21+
if (named_parameters == NULL) {
22+
named_parameters = "params771";
23+
}
1924

2025
OQS_KEX *k = malloc(sizeof(OQS_KEX));
2126
if (k == NULL) {
2227
return NULL;
2328
}
2429

25-
// initialize
26-
// char *input_params = "sample_params/public_params_771";
2730
public_params_t *params =
2831
(public_params_t *) malloc(2 * sizeof(public_params_t));
32+
if (params == NULL) {
33+
goto err;
34+
}
35+
2936
oqs_sidh_iqc_ref_public_params_init(params[0]);
3037
oqs_sidh_iqc_ref_public_params_init(params[1]);
3138

32-
if (!oqs_sidh_iqc_ref_public_params_read(params[0], params[1], "sample_params/public_params_771"))
33-
return NULL;
39+
const char **input = oqs_sidh_iqc_ref_params_from_name(named_parameters);
40+
if (input == NULL) {
41+
goto err_clear;
42+
}
43+
44+
if (!oqs_sidh_iqc_ref_public_params_read(params[0], params[1], input)) {
45+
goto err_clear;
46+
}
3447

3548
oqs_sidh_iqc_ref_fp_init_chararacteristic(params[0]->characteristic);
3649

@@ -40,7 +53,7 @@ OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand) {
4053
k->estimated_quantum_security = 128;
4154
k->seed = NULL;
4255
k->seed_len = 0;
43-
k->named_parameters = strdup("sample_params/public_params_771");
56+
k->named_parameters = strdup(named_parameters);
4457
k->params = params;
4558
k->ctx = NULL;
4659
k->alice_0 = &OQS_KEX_sidh_iqc_ref_alice_0;
@@ -50,6 +63,15 @@ OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand) {
5063
k->free = &OQS_KEX_sidh_iqc_ref_free;
5164

5265
return k;
66+
67+
err_clear:
68+
oqs_sidh_iqc_ref_public_params_clear(params[0]);
69+
oqs_sidh_iqc_ref_public_params_clear(params[1]);
70+
71+
err:
72+
free(params);
73+
free(k);
74+
return NULL;
5375
}
5476

5577
int OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv,
@@ -201,8 +223,10 @@ void OQS_KEX_sidh_iqc_ref_free(OQS_KEX *k) {
201223
oqs_sidh_iqc_ref_public_params_clear(((public_params_t *) (k->params))[0]);
202224
oqs_sidh_iqc_ref_public_params_clear(((public_params_t *) (k->params))[1]);
203225
free(k->params);
204-
k->ctx = NULL;
226+
k->params = NULL;
205227
free(k->method_name);
206228
k->method_name = NULL;
229+
free(k->named_parameters);
230+
k->named_parameters = NULL;
207231
free(k);
208232
}

src/kex_sidh_iqc_ref/kex_sidh_iqc_ref.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212
#include <oqs/kex.h>
1313
#include <oqs/rand.h>
1414

15-
OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand);
15+
OQS_KEX *OQS_KEX_sidh_iqc_ref_new(OQS_RAND *rand, const char *named_parameters);
1616

1717
int OQS_KEX_sidh_iqc_ref_alice_0(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len);
1818
int OQS_KEX_sidh_iqc_ref_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
#include "kex_sidh_iqc_ref_params.h"
4+
5+
typedef struct {
6+
const char *name;
7+
const char *params[10];
8+
} params_def;
9+
10+
// clang-format off
11+
const params_def all_params[] = {
12+
{
13+
"params46",
14+
{
15+
"p : 60183678025727",
16+
"E : y^2 = x^3 + (33377407586757 * i + 44218433491776) * x + (14267804413813 * i + 34113052821919)",
17+
"lA: 2",
18+
"eA: 22",
19+
"PA: (3621292231555 * i + 37993208494088, 7444041801194 * i + 49342879615307)",
20+
"QA: (42474562877393 * i + 53371276514445, 2096833973245 * i + 34935006825293)",
21+
"lB: 3",
22+
"eB: 15",
23+
"PB: (15834791163149 * i + 48632673242917, 26787723276578 * i + 2080970701160)",
24+
"QB: (41347477823487 * i + 16893996428645, 16353006256863 * i + 58871308637793)"
25+
}
26+
},
27+
{
28+
"params263",
29+
{
30+
"p : 13278338917780691403163453935679248163066204141424819568321422575495838416502783",
31+
"E : y^2 = x^3 + (10146232096640085910917654383121220722483913358884738813297160334128811466415525*i+12561065565697579851239386918801659303795666601356542822684985096240783059294353)*x + (5173097881985929355869345579251684505584624561073144550698251610858120795396524*i+7107679418274528586696192790945059679329002947961173384005281572895084003568218)",
32+
"lA: 2",
33+
"eA: 130",
34+
"PA: (1195124728519659060317276132092013999345554256425666367370465963951595701748339*i + 12098972036709468461769702810131237350914726908853501736574286596252384974205652, 9783772475920257416467468866150378267376245694752823265285613818169901942309758*i + 11347159712348451494564706572599934965946403356550033502368700150470499448870987)",
35+
"QA: (13205817885805264818436305084890835188490919868599289846511015770901764583677253*i + 5747572646648472262100078852868099320898697620053049578554081522615552834142382, 11801682343040573989191884352262922625922977024975963745404870899756844108073781*i + 995065035530346107238957276796927946979246210950956147759509023538740100220494)",
36+
"lB: 3",
37+
"eB: 81",
38+
"PB: (5344800255669587458309912385997503623935901519546261901204157001079956379346933*i + 4377688844822469620769951245537289173274736372423169606270308984109645753298367, 6652276474756696057821879367411351758786745790244544252917780253177388224676512*i + 6708409928090950067466623637647088247028372838873736207829979327577754417492323)",
39+
"QB: (5394161621076087291764603321428338049084294313968048256313378341079709241759382*i + 11839282739753708776384780179031575074752559110018400195581350405443930573103478, 13250321748367194013481592159238890438519376028036613608154243555537109237538486*i + 5018156126061581597984382235576466750307112019427938373002833669914648135622879)"
40+
}
41+
},
42+
{
43+
"params521",
44+
{
45+
"p : 5646428529833603710854376801719732121889771686125102421349898409102848702003905102057129871853579459735758942656769724874115169484320460874488881525976727551",
46+
"E : y^2 = x^3 + (749284552715987846148963973296050195126229569341142224654666772427960869882697237787535113296933915107646826510805251959952317725821624926383192023779227916*i+4450862168665197219135947325665108840719206715065697554561201799074300990784248608236935291171911258967881216685164820345027022153809546719817771293646383402)*x + (2090701186560231235295975659537182225064154823783034367876346818451609525370628921026656891712603865222854303410638520367213822274197422708317359681412801686*i+928331116130151780314451251635374082476545231185861659046556547242876069870814548070746611568992085667981514874929668958586384832118048434225604407758374282)",
47+
"lA: 2",
48+
"eA: 258",
49+
"PA: (4099566244205693793351119863629118684504739011975746402268940060566068632610815266810397027797757094816929218567651253950072216325440815687610023993835084896*i + 1558017772998619899443036875935946235185689333987633624537644882488763783158554538347022310514300405167644627965823931934377803788161014061154800653636626931, 4309963503463625615680726988334053841208952164733703323705989592325431854359074218382917880219717866947948218257035199142577782828393068620191995480863080814*i + 371139087724151319343471759858355552237686119972572871121509307705868621618190178855645217401101942092226237837619601742237974591506374361483536984282167861)",
50+
"QA: (1068668697541208179714192612921089347931894414290359842562082470165052062241629674686530102495737378212525479245784252461983051355518227298502808569246918728*i + 3439758296201500299118396242846510199830393172149382335887091564620130903972985332523718369650346601985540123834734249105539074407495456634862920938577617312, 1377114633894100174167466575056453645918713530999472681191914854993325497527119824352424425031078252594689770391880104513192317018010057467691025379460070671*i + 4932622986840321005380766859714312144000718130204073302754586852541324804616229501269099878044960212632820224170853684078869359092914886360672352750928115581)",
51+
"lB: 3",
52+
"eB: 161",
53+
"PB: (1873601143875829767876930991819826178988629054425671567488176037109831662817961473686026144306947256312476316751547084289880741326649856082832561714610850944*i + 1560175318533519875886314144935322002014985257654221707041583923868859979591849198401249634353361077499233198751747045058302746944304448268907689086502178616, 4982994975025169124121736752171094366264972439763192439008272414941290947933013927951198144521578535758162978083130741822789277050594650669549067865269480720*i + 5276260709601376725929198456951440724276715138987805447686932240717621617089316893818094566900580557346731678327745302440662762271627385800896501795127323769)",
54+
"QB: (697646709404910236660735870475422491121726200391885074740251760174191839071888445718446637282034941836922171390196797602747505117748596104805560163856490804*i + 3625576702015594834652275264908614642470435266304155762812699923280767886451566560460365242828862442624975825786369269113406701427398318872227046324990780609, 4066773540363717441440268891591433184568174886592697891244632377954091519594774358483000191238791345767299029423088482812653880802118173619454377886226640626*i + 4190003034380720563592676434553383980850520959077934081654167677748426947392920518786394581045699661017779519240551462796264093681413592624709890262004623150)"
55+
}
56+
},
57+
{
58+
"params771",
59+
{
60+
"p : 9161191555982008052298538759697325872858383005444503030763917191888120427263653604739574602371851919945332710234806205297475768266460658683484318356498713773944703702864057467786913144364234277796785269800198817400814717913480036351",
61+
"E : y^2 = x^3 + (834414288954992257633455994192711449929625512434805347027412475310171948875352369017186937444645005409828817983476510572586689796723205608064400704385270116308944492168385499542550868452776212626111499661118550170888024552876875729*i+6422246000772528873002015578224375300444670334298744905928223359513938843110113655634334268879522218663819121887750824098836054966064056104287198717041277477329053582144813207672147369924203318339728355843554541603191165928512397074)*x + (6952862402661321818296934608460489441319492072429008834217170925899505712694617760090534612163651714423387662001257443691685988562319647888954263195545834510820670121276853179853453135161349568882745925527747286264586000816122662211*i+1801461307959256058754493292728237821856779795303869606357346421878164668617118529630863155614277813374785952465141324739461376333648338471745996274618770379494305097783365807731152848487472399799827998470890201827624741461111844749)",
62+
"lA: 2",
63+
"eA: 386",
64+
"PA: (8104593598414300086705087098908311675030394399959710332294184564762361863835814307651327024806690095568546280563692186849608460564606528773115207348687739021740029922619947714003573784888374548470687911506820492526985145356335776446*i + 632723349492681895135768435670357424582748082370711990704098097526814363254991414123449305576539513413267774301605548017161074510859073483979044361740779150098452314120335316096416597425252882878881588818896781804191220848731008911, 6034454472695438020325443031188950458345445112930585331722482288319997086142640364760979210290700670085317874428427766978327706213014073448960161802245001428613528860063394247112544226096847944993689243523414240839321526974724280084*i + 3376800547075148066131970733541260743185153743453912100162319249600572606491084521062090319658073231669236186390422247468127880255567740549554667385892315318084299520660699776774656198376921140804260118165199828142540405774846853362)",
65+
"QA: (2765053530820933445180998871832795313413946616218824127593215418859013295660994609348273546952174346166291903038023352135058779784133949653750586420316372475215070348272866065120539728715859798970386824706592072979142529191135265323*i + 4732630024306258879927225136904171174931421517225731042645253305380470569884989406374249571295113204909266761424593068942210539695621294791558555039840356194123377363470161894673618251481432584334320864233790205509164494505329331140, 4708584843807409676003733183136845288008597122413250473476957203240325041335536376819164132204831789648003763063194049792870695914267484368767687682889171445457695974399304884657394666807097601382128550039198416659937221320896980595*i + 6104437072476030203734870744361913380396342850775889826642334399814339224961644051070388756974954400647041041004040997989961961816982978689836414675142946310418861822777207486737128660492374354598010889893873060781304652392500710082)",
66+
"lB: 3",
67+
"eB: 242",
68+
"PB: (3723895349260758944309889666952259909100424286764560948312844268916772080039091215194337476636106420561414206591006321840112505108525982835492286766266110460566937541551059011352798312867785900902951383836578444811900436603779674156*i + 8743733696371247709279217014221258693400652288884395784267041686740452975091187425123471886102340505926375682973850553993788314479705338557349284829716634286210825839825870379330100097103593148671390855900137936801780665161878467993, 8424241650394632026078421716292833598872223719053431149109783663376931645995151278886785513466077121063748132909299925706619410172763350254899661370368971798311266097772796416940961537063436478392108549760549489321636110323643921123*i + 5374610701506876802640722880318277643810083668249556787469960695884056089879250039154916755196748541850985290281804798435130927222521567170894905772855374873224510597225929994186728464447646660504589278345473514974074045904197344273)",
69+
"QB: (7981195513789185488304157075392399068225052449489399943063249773724560281912789833792310612686835775356813196319643714519912123781500389027567621573946130157326769787082613646934296091151487953874493791717298439146548339580934348575*i + 6959299245778867305112554827985507377113662771316265280990751282080086185858550157506531552361757479904416443825479048359163719118671413144273420888615839877660288012435298448942304481059091585291706567711227879486375625133765783910, 4336888647745442057861067196613721067586889048321014506728806821392030059558638097842307835657146159647787621123250859783441147632121339894258934458102109985684014691372520469809743302874968486912740925764328254939284436994206821845*i + 219245698132319235934495637714582743670714862281024333766283207034829039474459867538486706426384326703893620364910932534607493596118208826082598798090838576408297983032654112984263431060439529497966028364279027386883785406090014775)"
70+
}
71+
}
72+
};
73+
// clang-format on
74+
75+
const char **oqs_sidh_iqc_ref_params_from_name(const char *named_parameters) {
76+
static const size_t elements = sizeof(all_params) / sizeof(all_params[0]);
77+
78+
for (unsigned int i = 0; i < elements; ++i) {
79+
if (0 == strcmp(all_params[i].name, named_parameters)) {
80+
return (const char **) all_params[i].params;
81+
}
82+
}
83+
84+
return NULL;
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef KEX_SIDH_IQC_REF_PARAMS_H
2+
#define KEX_SIDH_IQC_REF_PARAMS_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
const char **oqs_sidh_iqc_ref_params_from_name(const char *named_parameters);
9+
10+
#ifdef __cplusplus
11+
}
12+
#endif
13+
14+
#endif

src/kex_sidh_iqc_ref/sample_params/public_params_263

-10
This file was deleted.

src/kex_sidh_iqc_ref/sample_params/public_params_46

-10
This file was deleted.

0 commit comments

Comments
 (0)