Commit 7e7f58d0 authored by Stephane Glondu's avatar Stephane Glondu

load_election_and_verify_it_all

parent 24446476
{"num_tallied": 2, "tally": [[{"alpha": "6140145258556358661397492590955128913066385478756625008821418765986348367416109713440679922490386641555094007531536755286457454043337459062250953027955586899216206497663112184643059323699179808924908573326425375460164133010778684602102518656731897332287999463208730350918969950869068379490551326292127220592492055778054848882392507841201406457902077332941143418651463052897378710596285370000349226260580171661846182665707964437059409661998424121482884191763290338045303612721375028981371111759622499042228499581664373581328657686672944718657827179940285202905648432276017828729647405121756504875357166179318194063540", "beta": "11152039015378680335374164368722711910234220626398792914675632431484071946915762974719904361626552766864644873233905337251796923349700962676710949559759349014041754251510308738532344724894851261657934697049826359020534432610254771328964054082545109608538683389373531090567786761115603508848981765307657702444453022949315869926051765697264413764775899717169226548166837755169433439152505597639251325160282449397596948335076838462607631386989480912106957090632699417079612597661093130925299897124218200601435563402879670199511540448241661378286440310612509469291796109294318564205539239547298523235163835846445057530661"}, {"alpha": "9833817723491828772512918220169665172302710674018239981452598568308081832541776383648438445799643312195675731702939657743025544536882461171799934135766807925751840711330829780038128928884383845342130584859019214951283111790321162398479988074268957383567336282665625062285790791403984081026606465754724165646028962035817436904066341531400918879204560326826508564419491179601871192688223629851384425737785066501917825592218032079754414319219040322247188851242911635996311129123067658479051649609200070481849389611968112614169046214557378773381903310807293465147023406901015973449456393971662883143458040649269573975034", "beta": "4996299618104043547385649616963508204464297435901910775541744807844643987237306128698054633679765391278936435822571949589042879484139826491245269348371572748405631448389435367719580410865778278966485311738659214115998861663201848985213628130494420928622515553422794109832707308235259102691453450545090010337557971273813016647102853723503594783550475359083391616213477673387949181737133260633245943953128165905959262578823492087197294219896613989917994052296169408240744351807211417567401070517935252428436310267281637874851493751622616232768435061680829080073336933358651408569096241421469093617039828477431391398782"}, {"alpha": "13864082943735491413234258161363087887054585629092144112685045775971705909876813042366420674399791076366957185460383633381423655501464091467015739494215284320550350835830493523689555782636539870269606454225905619745835677541202773190553374630275030300814629851321203875624549272646609442144701699105929348324163423941669557739662679366043795227625464926650984387276629559238648981510925876403959580792094157983668939576520376724825735929853637082352755662732950594630543926951958240995157274496629786946103576399335193678004294245169183050549875676636122522333233235633915924094713273616229168293551215525510267149794", "beta": "11908944031071116237214816986793958685665329347715453752036319249926164137569628695456149891545696168394964987681627674587438872950918529495211222149664677788944972601633280104985742659602662636536777608000884696581561179915703795597890245498871496366877952073350276776706442894372345102375251690120490916067042194249344530925940505449041184432632644337609050915486146215689080860066255515630733972798017024769982518044885333028109456716797968592250327798866056503424507495672948371890457574112594164473569142307040019246141863446232938983689714531181668747207755829850611075937339719124292812324437595021080421288706"}, {"alpha": "7747649359162937428657473999014977986828318086776081862786597746183161949141327966054605025699278054102778387706589210339235025828070507473056554149213549402089023932615233323918618597032315467307487112459911341598374721259176573853527304134248968649503245589233252720146548815914336397095718344869311150797963927888564025309875661478359335823921679280480917534464880784291074772214071582888847034162475235605050852719164981745887607787209933157934650983775868038621348947320943294938925740838976337263207178611762607965886857464883906291847946838244760412161263223925744960654900938785387666615781682120030783341414", "beta": "12981646949055218272687690847406983669373058365755404137393187770798495202019417154486352340302298521152980001711714976901593062239091284486538901849433645402417067945612467365522350099764578387851492679834560420143983329281151512772338636151349348266889517642550114129098203998142881409250144071677062987426064840748430433656235255627088502398172257156457140502432585790520244547575969577227987493199999813343908708656545305549360431647551145655322285508529901198566823717948238428062836254031325982869863001223899744761969049824231274688553861690430289259212934060886396220009710153863934727520851486975134710673827"}]]}
\ No newline at end of file
{"decryption_factors": [["2456206064889148267733873384674102957864188191916919989673760852748506494039652400693498164117348676106114222278560829091010708313224238336901443383927877294752218104619146310674582617675357738704010976661495170180694672629300150164344545411895446859254815618443096985090909927599284330538476926968661233723347348234276364802034764545659918112716554577006922216581287495803063985112963482075489023049181208787181100765975344012417375263373825028726672453139890470829189886199934377547677469537404343583465028803749722626168552235972546818171436917002174512503493562521213040827115960164264726694478787118623546350774", "4996299618104043547385649616963508204464297435901910775541744807844643987237306128698054633679765391278936435822571949589042879484139826491245269348371572748405631448389435367719580410865778278966485311738659214115998861663201848985213628130494420928622515553422794109832707308235259102691453450545090010337557971273813016647102853723503594783550475359083391616213477673387949181737133260633245943953128165905959262578823492087197294219896613989917994052296169408240744351807211417567401070517935252428436310267281637874851493751622616232768435061680829080073336933358651408569096241421469093617039828477431391398782", "11908944031071116237214816986793958685665329347715453752036319249926164137569628695456149891545696168394964987681627674587438872950918529495211222149664677788944972601633280104985742659602662636536777608000884696581561179915703795597890245498871496366877952073350276776706442894372345102375251690120490916067042194249344530925940505449041184432632644337609050915486146215689080860066255515630733972798017024769982518044885333028109456716797968592250327798866056503424507495672948371890457574112594164473569142307040019246141863446232938983689714531181668747207755829850611075937339719124292812324437595021080421288706", "12981646949055218272687690847406983669373058365755404137393187770798495202019417154486352340302298521152980001711714976901593062239091284486538901849433645402417067945612467365522350099764578387851492679834560420143983329281151512772338636151349348266889517642550114129098203998142881409250144071677062987426064840748430433656235255627088502398172257156457140502432585790520244547575969577227987493199999813343908708656545305549360431647551145655322285508529901198566823717948238428062836254031325982869863001223899744761969049824231274688553861690430289259212934060886396220009710153863934727520851486975134710673827"]], "decryption_proofs": [[{"challenge": "678086184040171943096099169802629299422307686247", "commitment": {"A": "13825747775616499365187124191392992377334694351294323748244171687660062898468696111316448831384120185577196397917007198558817169610565296738055373236055245346755464323251542687666480166259184586322989363799041433186338876446306097105408307007622820894385902531849007085501101109333569247408334118662269720962964668514885609034875666240424040043678897057042727090628362080499201984200472174435756902830245346207905509700305453989961750393376228747621874321138928477010135894585800855407160963767114913093998057884495290127104719648171902013107583561695124849981318523339299531311611564829904734295968796117759695975688", "B": "2457059796239429136050893831528866674029001288512085730168645624504209763282987349883708363854774360284359410087873729574047910889124598179216591397525449407150343531511668513556384628012147474407675561074154830756859507345128306207107220280062383892022971070029526592016766857575218435368438328139834702454522217982793204307571573956835233993891595772102251371533164822987944913844538619316259172041238507803304044138032223567168690787961104373335644900015901676910777871077094149249194344609337037838692728339172052430704362901532427610223059707369606747150306157808565204736273657930241799427984593708654801633904"}, "response": "35811314873829021681541502329592415910046259687906578373182348113354062667915"}, {"challenge": "570281701840454923284027789846112979267489519725", "commitment": {"A": "9009605155635164991255172763330527132956599635605679706799280350219449102655777726276779948555407916789053719435870774544942810615609746761591053842976791400078535439903175773812241374926735877415714242182072409514727941731061721176008380004617931029773581373005474062906424042283088813169439061985522486098993918022714146234049075132984434337168392159997779146904626515821449663507885157758571432339366919837224124233703510327240757076604978282962895468679458590555964646327912503730563425263251154307134306464496769856817573560019997691758667242701012938554668054561932365140451722447769060201235164353508496018396", "B": "7095152566470941797210233741364523285244242879274571062121536455126250147180011673998224835812566212181198141870777685118545243241411272839390613278788178437354217584679405378867562172034416311132334367545658969203477217216275439296476258244025470421166376832217289652596060614951355939534612065731937483590122089126929635427557020351601186295400798533639939803300366822632554251023139327129163209179864474999689145398690706541568542833764798672852328617854487572277101815505215586447780482700753571948678823235035779346202046111463143156984703388114634355359973372838756480028440739156838861237438337985901218835435"}, "response": "45300289979028305574348174344057698461327945273923831256513000288382251526757"}, {"challenge": "551088702665035847668902747883580511343061020504", "commitment": {"A": "10778736316897590180541172474445359044019885062490352464971033605997975875784289971977144645999917189632298526068180185813568831338178345714154995341782912732716425942910344958795291331177554698208302840777652462737668968281522366295717940950554049383559908122685609504495516521123980227729564091398377808073212102701522374269000531223102623914217551720024907670795974386695325568746529614740678508133221691502573143462611940521370164173630763155043331206439823308423854292001980626704566124212303821849371191527928408057672224010101370602334328006486596876205889500039522808028806550164445878819796883043073534891215", "B": "15242288353753305495679821690238123601579697279980388222741066749831796865558214484621883934906261177171379734158780861193802557183665496441228293979704803042494636082948166771376647887345381354300080298444969063102937129031830879895076002068297621198006456753714439282666307684465519551512622247026418248104253216682572523499865572010036665137943356750542363284219735694110245490137929901167012599838242720210177809980011078237998139327334112674566350544212881461973525199214117088299189290117933216971482344402470372419684612444965293340531389951153249408328495964015764750772612119375449163427433087648140094541012"}, "response": "42167731011751868639490671056051361672311216908513555777417071302435770215499"}, {"challenge": "1251576275849831109511918160200878210397028110487", "commitment": {"A": "13874750434619143650030341724267269076679613616545665657669633629205783211626877086978592440586502033399984637631380924422289144754809623223494693537696374791983279788172963893382700321523712851148616111870861147192475524292037962720703602697060212390290027549521815861554037810634338971447454920157384316693718613953783577198846768143723913276743953828938884329574877818938428019115597288933143910922435527717101579774992770071697866947528216911670114262202798817155110932527330898240339503898551556179099462562961563238800041661447365761292688771416278892026945393500118070439602417241951884585974499560753445928494", "B": "169355357549814133082110402968746543446121220332350479783679375515241428274697669069900277336734473111079401776325819361525579597645941494823378210151954278111533232764693487016900406744659136186062936789383070032107261425817943552071679906769688121472338678974380972549334643239849691345856235726324649553532000473883577116590982002047000225156279778901561228603719330861935923662151954575556399274842722078533851259001773354370469226456706666050981384797947970710098795540280970634522707171073986983444910522413288014927081452379575272597307526870018406512173391896173078158589593204776419104414087673924223008330"}, "response": "7076413782510726331122881849131639413726363163828763490947313704514185325881"}]]}
\ No newline at end of file
{"trustee_private_keys": [{"public_key": {"g": "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533", "p": "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071", "q": "61329566248342901292543872769978950870633559608669337131139375508370458778917", "y": "13413536485360596162117509074825082492146422492336993983220767543096612667335041152907231513824044913738906152541149857849737067859185342543622448311556712416080079971431641185273833852441264325481867696726488289145101401983297121479711309538219588042218732878057915656901430381090815194156076478057863101546026469415161926364987580263384129731992815360337654952915225618017615855899362635782363403142334181880226311848845722133441630063825175283518292350982441101548617569316612942610433088353640302787748937007618067190197809928467303825082570918742798139091993351332364996141428976368902435802194163628302762629032"}, "x": "45298523167338358817538343074024028933886309805828157085973885299032584889325"}]}
\ No newline at end of file
This diff is collapsed.
{"public_key": {"g": "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533", "p": "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071", "q": "61329566248342901292543872769978950870633559608669337131139375508370458778917", "y": "13413536485360596162117509074825082492146422492336993983220767543096612667335041152907231513824044913738906152541149857849737067859185342543622448311556712416080079971431641185273833852441264325481867696726488289145101401983297121479711309538219588042218732878057915656901430381090815194156076478057863101546026469415161926364987580263384129731992815360337654952915225618017615855899362635782363403142334181880226311848845722133441630063825175283518292350982441101548617569316612942610433088353640302787748937007618067190197809928467303825082570918742798139091993351332364996141428976368902435802194163628302762629032"}, "x": "45298523167338358817538343074024028933886309805828157085973885299032584889325"}
\ No newline at end of file
{"pok": {"challenge": "1269799557842253837797565878970695136921780853765", "commitment": "6262557888228969774774105688609114060918909614275626686586335457847573786400747768036526171167101489823347104074280871100921259532398195056570273190892264651528234448390963378245380395419272284582740525289074670273888264168250963643953453682369732003620414683190541116972018020646749325413456858071671357590900448623415044095801154541494764663055852884958354978070881404644285376015835373875228524584106688638847711514091446083928236492823000470600276392847367617105585573278776948748855125221944145107583698553994679319007286323978299866371261050678788209668489351085023347378700912536737539380963786431729936177579", "response": "4858904720300716925304227178612738017119587177822453389202332633404192506142"}, "public_key": {"g": "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533", "p": "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071", "q": "61329566248342901292543872769978950870633559608669337131139375508370458778917", "y": "13413536485360596162117509074825082492146422492336993983220767543096612667335041152907231513824044913738906152541149857849737067859185342543622448311556712416080079971431641185273833852441264325481867696726488289145101401983297121479711309538219588042218732878057915656901430381090815194156076478057863101546026469415161926364987580263384129731992815360337654952915225618017615855899362635782363403142334181880226311848845722133441630063825175283518292350982441101548617569316612942610433088353640302787748937007618067190197809928467303825082570918742798139091993351332364996141428976368902435802194163628302762629032"}}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -10,6 +10,8 @@ module type TYPES = sig ...@@ -10,6 +10,8 @@ module type TYPES = sig
val vote : vote t val vote : vote t
val encrypted_tally : encrypted_tally t val encrypted_tally : encrypted_tally t
val partial_decryption : partial_decryption t val partial_decryption : partial_decryption t
val election_public_data : election_public_data t
val election_private_data : election_private_data t
end end
module Types : TYPES = struct module Types : TYPES = struct
...@@ -23,6 +25,8 @@ module Types : TYPES = struct ...@@ -23,6 +25,8 @@ module Types : TYPES = struct
let vote = (read_vote, write_vote) let vote = (read_vote, write_vote)
let encrypted_tally = (read_encrypted_tally, write_encrypted_tally) let encrypted_tally = (read_encrypted_tally, write_encrypted_tally)
let partial_decryption = (read_partial_decryption, write_partial_decryption) let partial_decryption = (read_partial_decryption, write_partial_decryption)
let election_public_data = (read_election_public_data, write_election_public_data)
let election_private_data = (read_election_private_data, write_election_private_data)
end end
let load typ fname = let load typ fname =
...@@ -40,7 +44,8 @@ let save typ fname x = ...@@ -40,7 +44,8 @@ let save typ fname x =
Bi_outbuf.flush_channel_writer buf; Bi_outbuf.flush_channel_writer buf;
close_out o close_out o
let load_and_check typ fname = let load_and_check ?(verbose=false) typ fname =
if verbose then Printf.eprintf "Loading and checking %s...\n%!" fname;
let thing = load typ fname in let thing = load typ fname in
let tempfname = Filename.temp_file "belenios" ".json" in let tempfname = Filename.temp_file "belenios" ".json" in
save typ tempfname thing; save typ tempfname thing;
...@@ -49,14 +54,26 @@ let load_and_check typ fname = ...@@ -49,14 +54,26 @@ let load_and_check typ fname =
Sys.remove tempfname; Sys.remove tempfname;
thing thing
let data x = Filename.concat "tests/data/favorite-editor" x type election_test_data = {
let one_election = load_and_check Types.election (data "election.json") raw_json : string;
let one_trustee_private_key = load_and_check Types.private_key (data "trustee-private-key.json") election : election;
let one_trustee_public_key = load_and_check Types.trustee_public_key (data "trustee-public-key.json") public_data : election_public_data;
let vote_1 = load_and_check Types.vote (data "vote-emacs-1.json") private_data : election_private_data;
let vote_2 = load_and_check Types.vote (data "vote-emacs-2.json") }
let encrypted_tally = load_and_check Types.encrypted_tally (data "encrypted-tally.json")
let one_partial_decryption = load_and_check Types.partial_decryption (data "partial-decryption.json") let first_line filename =
let i = open_in filename in
let r = input_line i in
close_in i;
r
let load_election_test_data ?(verbose=false) dirname =
let data x = Filename.concat dirname x in
let raw_json = first_line (data "election.json") in
let election = load_and_check ~verbose Types.election (data "election.json") in
let public_data = load_and_check ~verbose Types.election_public_data (data "public_data.json") in
let private_data = load_and_check ~verbose Types.election_private_data (data "private_data.json") in
{ raw_json; election; public_data; private_data }
let ( |> ) x f = f x let ( |> ) x f = f x
let ( =~ ) = Z.equal let ( =~ ) = Z.equal
...@@ -72,8 +89,6 @@ let verify_public_key {g; p; q; y} = ...@@ -72,8 +89,6 @@ let verify_public_key {g; p; q; y} =
check_subgroup p q g && check_subgroup p q g &&
check_subgroup p q y check_subgroup p q y
let () = assert (verify_public_key one_trustee_public_key.trustee_public_key)
let hashZ x = Cryptokit.(x |> let hashZ x = Cryptokit.(x |>
hash_string (Hash.sha1 ()) |> hash_string (Hash.sha1 ()) |>
transform_string (Hexa.encode ()) |> transform_string (Hexa.encode ()) |>
...@@ -171,6 +186,19 @@ let compute_encrypted_tally e vs = ...@@ -171,6 +186,19 @@ let compute_encrypted_tally e vs =
) e.e_questions in ) e.e_questions in
{ num_tallied; tally } { num_tallied; tally }
let () = assert (verify_vote one_election vote_1) let verbose_assert msg it =
let () = assert (verify_vote one_election vote_2) Printf.eprintf "Verifying %s...%!" msg;
let () = assert (compute_encrypted_tally one_election [| vote_1; vote_2 |] = encrypted_tally) let r = Lazy.force it in
Printf.eprintf " %s\n%!" (if r then "OK" else "failed!")
let load_election_and_verify_it_all dirname =
let e = load_election_test_data ~verbose:true dirname in
verbose_assert "election public key"
(lazy (verify_public_key e.election.e_public_key));
Array.iter (fun x -> verbose_assert "vote"
(lazy (verify_vote e.election x))) e.public_data.votes;
verbose_assert "encrypted tally"
(lazy (e.public_data.encrypted_tally =
compute_encrypted_tally e.election e.public_data.votes));;
let () = load_election_and_verify_it_all "tests/data/favorite-editor"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment