2 Module : Gargantext.Prelude.Crypto.Share
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 # Random work/research (WIP)
12 Goal: share secretly a sequence of random actions (either [Bool] or
13 [Ordering] for instances here) but without sharing secrets.
15 Motivation: useful to share clustering algorithm reproduction using BAC
16 (Ballades Aléatoires Courtes).
18 Question: how to certify the author of such (random) actions ? Solution
23 ------------------------------------------------------------------------
24 {-# OPTIONS_GHC -fno-warn-orphans #-}
25 ------------------------------------------------------------------------
26 module Gargantext.Prelude.Crypto.Share
31 import Prelude (fromEnum, toEnum)
32 import Gargantext.Core.Types (Ordering)
33 import Gargantext.Prelude
35 ------------------------------------------------------------------------
37 newtype Seed = Seed Int
41 ------------------------------------------------------------------------
42 instance Random Ordering where
44 case randomR (fromEnum a, fromEnum b) g of
45 (x, g') -> (toEnum x, g')
46 random g = randomR (minBound, maxBound) g
49 randomOrdering :: Maybe Seed -> Int -> IO [Ordering]
50 randomOrdering = randomWith
52 randomBool :: Maybe Seed -> Int -> IO [Bool]
53 randomBool= randomWith
55 ------------------------------------------------------------------
57 randomWith :: Random a => Maybe Seed -> Int -> IO [a]
58 randomWith seed n = do
61 Just (Seed s) -> pure $ mkStdGen s
63 pure $ take n $ (randoms g)
65 genWith :: Private -> Public -> Int -> IO [Bool]
66 genWith privateSeed publicSeed n = do
67 xs <- randomBool (Just privateSeed) n
68 ys <- randomBool (Just publicSeed ) n
69 pure $ zipWith xor xs ys
73 searchSeeds :: Int -> IO [Int]
74 searchSeeds xs = mapM (\n -> randomWith (Just n) l) [1..]
80 certifySeed = undefined