Commit 89cd91f8 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Remove hard-coded default group

parent 7b80aa6e
......@@ -21,19 +21,23 @@ DIR=$BELENIOS/demo/data/$UUID
mkdir $DIR
cd $DIR
# Common options
uuid="--uuid $UUID"
group="--group $BELENIOS/demo/groups/default.json"
# Generate credentials
belenios-tool credgen --uuid $UUID --count 3
belenios-tool credgen $uuid $group --count 3
mv *.pubcreds public_creds.txt
mv *.privcreds private_creds.txt
# Generate trustee keys
belenios-tool trustee-keygen
belenios-tool trustee-keygen
belenios-tool trustee-keygen
belenios-tool trustee-keygen $group
belenios-tool trustee-keygen $group
belenios-tool trustee-keygen $group
cat *.pubkey > public_keys.jsons
# Generate election parameters
belenios-tool mkelection --uuid $UUID --group $BELENIOS/demo/groups/default.json --template $BELENIOS/demo/templates/election.json
belenios-tool mkelection $uuid $group --template $BELENIOS/demo/templates/election.json
header "Simulate votes"
......
......@@ -30,33 +30,23 @@ let remove_dashes x =
done;
Buffer.contents res
let derive uuid x =
let do_derive uuid x =
let open Cryptokit in
let uuid = remove_dashes (Uuidm.to_string uuid) in
let salt = transform_string (Hexa.decode ()) uuid in
pbkdf2 ~prf:MAC.hmac_sha256 ~iterations:1000 ~size:1 ~salt x |>
transform_string (Hexa.encode ())
module RunCredgen (X : sig end) = struct
(* Setup group *)
module G = Election.DefaultGroup;;
assert (Election.check_finite_field G.group);;
(* Some helpers *)
(* Beware: the following must be changed in accordance with the booth! *)
let digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
let token_length = 14
let n58 = Z.of_int 58
let n53 = Z.of_int 53
module type PARAMS = sig
val group : (module Election.FF_GROUP)
val uuid : Uuidm.t
val count : int option ref
val file : string option ref
val derive : string option ref
val dir : string ref
end
let public_key_of_token uuid x =
let hex = derive uuid x in
let x = Z.(of_string_base 16 hex mod G.q) in
let y = G.(g **~ x) in
Z.to_string y
module GetParams (X : sig end) : PARAMS = struct
(* Argument parsing *)
......@@ -65,6 +55,7 @@ module RunCredgen (X : sig end) = struct
let count = ref None
let file = ref None
let derive = ref None
let group = ref None
let speclist = Arg.([
"--dir", String (fun s -> dir := s), "directory where output will be written";
......@@ -72,6 +63,7 @@ module RunCredgen (X : sig end) = struct
"--count", Int (fun i -> count := Some i), "number of credentials to generate";
"--file", String (fun s -> file := Some s), "file with list of identities";
"--derive", String (fun s -> derive := Some s), "derive public credential from given private one";
"--group", String (fun s -> group := Some s), "file with group parameters";
])
let usage_msg =
......@@ -83,6 +75,18 @@ module RunCredgen (X : sig end) = struct
let () = Arg.parse speclist anon_fun usage_msg
let group = match !group with
| None ->
Printf.eprintf "--group is missing!\n";
exit 1
| Some fname ->
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_ff_params ls lb in
close_in ic;
Election.finite_field r
let uuid = match !uuid with
| None ->
Printf.eprintf "UUID is missing!\n";
......@@ -94,6 +98,28 @@ module RunCredgen (X : sig end) = struct
Printf.eprintf "UUID is invalid!\n";
exit 1
end
module RunCredgen (P : PARAMS) (G : Election.FF_GROUP) = struct
open P
(* Check the group *)
let () = assert (Election.check_finite_field G.group)
(* Some helpers *)
(* Beware: the following must be changed in accordance with the booth! *)
let digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
let token_length = 14
let n58 = Z.of_int 58
let n53 = Z.of_int 53
let public_key_of_token uuid x =
let hex = do_derive uuid x in
let x = Z.(of_string_base 16 hex mod G.q) in
let y = G.(g **~ x) in
Z.to_string y
let count, ids =
match !count, !file, !derive with
| Some i, None, None ->
......@@ -207,7 +233,10 @@ module RunCredgen (X : sig end) = struct
end
let derive = do_derive
let main () =
let module X = RunCredgen (struct end) in
let module P = GetParams (struct end) in
let module G = (val P.group : Election.FF_GROUP) in
let module X = RunCredgen (P) (G) in
()
......@@ -34,7 +34,7 @@ module GetParams (X : sig end) : PARAMS = struct
])
let usage_msg =
Printf.sprintf "Usage: %s trustee-keygen [--group <file>]" Sys.argv.(0)
Printf.sprintf "Usage: %s trustee-keygen --group <file>" Sys.argv.(0)
let usage () =
Arg.usage speclist usage_msg;
......@@ -47,7 +47,9 @@ module GetParams (X : sig end) : PARAMS = struct
let () = Arg.parse speclist anon_fun usage_msg
let group = match !group with
| None -> Election.((module DefaultGroup : FF_GROUP))
| None ->
Printf.eprintf "--group is missing!\n";
usage ()
| Some fname ->
let ic = open_in fname in
let ls = Yojson.init_lexer () in
......
......@@ -74,14 +74,6 @@ let finite_field group =
let group = group
end in (module G : FF_GROUP)
let default_ff_params = {
p = Z.of_string "16328632084933010002384055033805457329601614771185955389739167309086214800406465799038583634953752941675645562182498120750264980492381375579367675648771293800310370964745767014243638518442553823973482995267304044326777047662957480269391322789378384619428596446446984694306187644767462460965622580087564339212631775817895958409016676398975671266179637898557687317076177218843233150695157881061257053019133078545928983562221396313169622475509818442661047018436264806901023966236718367204710755935899013750306107738002364137917426595737403871114187750804346564731250609196846638183903982387884578266136503697493474682071";
q = Z.of_string "61329566248342901292543872769978950870633559608669337131139375508370458778917";
g = Z.of_string "14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533";
}
module DefaultGroup = (val finite_field default_ff_params : FF_GROUP)
(** Parameters *)
let check_election_public_key (type t) g e =
......
......@@ -35,9 +35,6 @@ val finite_field : Serializable_t.ff_params -> (module FF_GROUP)
val check_finite_field : Serializable_t.ff_params -> bool
(** Check consistency of finite field parameters. *)
module DefaultGroup : FF_GROUP
(** A sample group suitable for cryptography. *)
val check_election_public_key : (module GROUP with type t = 'a) ->
'a election -> bool
(** Check election public key. *)
......
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