{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Crypto.Lol.RLWE.RLWR where
import Crypto.Lol
import Control.Monad.Random
type Sample cm zq zp = (cm zq, cm zp)
type RLWRCtx cm zq zp =
(Cyclotomic (cm zq), Random (cm zq), Ring (cm zq), RescaleCyc cm zq zp)
sample :: (RLWRCtx cm zq zp, MonadRandom rnd)
=> cm zq -> rnd (Sample cm zq zp)
sample s = let s' = adviseCRT s in do
a <- getRandom
return (a, roundedProd s' a)
roundedProd :: (RLWRCtx cm zq zp) => cm zq -> cm zq -> cm zp
{-# INLINABLE roundedProd #-}
roundedProd s = let s' = adviseCRT s in \a -> rescaleCyc Dec $ a * s'