(**************************************************************************)
(*                                BELENIOS                                *)
(*                                                                        *)
   Copyright © 2012 - 2022                                            
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
   it under the terms of the GNU Affero General Public License as        
   published by the Free Software Foundation , either version 3 of the    
(*  License, or (at your option) any later version, with the additional   *)
   exemption that compiling , linking , and/or using OpenSSL is allowed .   
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful, but   *)
(*  WITHOUT ANY WARRANTY; without even the implied warranty of            *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *)
(*  Affero General Public License for more details.                       *)
(*                                                                        *)
   You should have received a copy of the GNU Affero General Public      
(*  License along with this program.  If not, see                         *)
(*  </>.                                       *)
(**************************************************************************)

open Belenios_platform
open Platform
open Belenios_core
open Common

let prng = lazy (pseudo_rng (random_string secure_rng 16))

let random q =
  let size = bytes_to_sample q in
  let r = random_string (Lazy.force prng) size in
  Z.(of_bits r mod q)

************************************************************************
                                BELENIOS                                
                                                                        
                                                                        
  This program is free software: you can redistribute it and/or modify  
  License, or (at your option) any later version, with the additional   
                                                                        
  This program is distributed in the hope that it will be useful, but   
  WITHOUT ANY WARRANTY; without even the implied warranty of            
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     
  Affero General Public License for more details.                       
                                                                        
  License along with this program.  If not, see                         
  </>.                                       
************************************************************************
   Copyright © 2012 - 2022                                            
   it under the terms of the GNU Affero General Public License as        
   published by the Free Software Foundation , either version 3 of the    
   exemption that compiling , linking , and/or using OpenSSL is allowed .   
   You should have received a copy of the GNU Affero General Public      

open Belenios_platform
open Platform
open Belenios_core
open Common

let prng = lazy (pseudo_rng (random_string secure_rng 16))

let random q =
  let size = bytes_to_sample q in
  let r = random_string (Lazy.force prng) size in
  Z.(of_bits r mod q)
