Return to bliss_sampler.h CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / plugins / bliss |
1.1 misho 1: /* 2: * Copyright (C) 2014 Andreas Steffen 3: * HSR Hochschule fuer Technik Rapperswil 4: * 5: * This program is free software; you can redistribute it and/or modify it 6: * under the terms of the GNU General Public License as published by the 7: * Free Software Foundation; either version 2 of the License, or (at your 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 9: * 10: * This program is distributed in the hope that it will be useful, but 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13: * for more details. 14: */ 15: 16: /** 17: * @defgroup bliss_sampler bliss_sampler 18: * @{ @ingroup bliss_p 19: */ 20: 21: #ifndef BLISS_SAMPLER_H_ 22: #define BLISS_SAMPLER_H_ 23: 24: typedef struct bliss_sampler_t bliss_sampler_t; 25: 26: #include "bliss_param_set.h" 27: 28: #include <library.h> 29: #include <crypto/hashers/hasher.h> 30: 31: /** 32: * Implementation various rejection sampling algorithms. 33: */ 34: struct bliss_sampler_t { 35: 36: /** 37: * Sample according to exp(-x/(2*sigma^2)) 38: * 39: * @param x Value to be sampled 40: * @param accepted TRUE if value is accepted, FALSE if rejected 41: * @result TRUE if sampling was successful 42: */ 43: bool (*bernoulli_exp)(bliss_sampler_t *this, uint32_t x, bool *accepted); 44: 45: /** 46: * Sample according to 1/cosh(x/sigma^2) 47: * 48: * @param x Value to be sampled 49: * @param accepted TRUE if value is accepted, FALSE if rejected 50: * @result TRUE if sampling was successful 51: */ 52: bool (*bernoulli_cosh)(bliss_sampler_t *this, int32_t x, bool *accepted); 53: 54: /** 55: * Sample according to 2^(-x^2) for positive x 56: * 57: * @param x Generated value 58: * @result TRUE if sampling was successful 59: */ 60: bool (*pos_binary)(bliss_sampler_t *this, uint32_t *x); 61: 62: /** 63: * Sample according to the Gaussian distribution exp(-x^2/(2*sigma^2)) 64: * 65: * @param z Generated value with Gaussian distribution 66: * @result TRUE if sampling was successful 67: */ 68: bool (*gaussian)(bliss_sampler_t *this, int32_t *z); 69: 70: /** 71: * Sample the sign according to the binary distribution 72: * 73: * @param positive TRUE if positive 74: * @result TRUE if sampling was successful 75: */ 76: bool (*sign)(bliss_sampler_t *this, bool *positive); 77: 78: /** 79: * Destroy bliss_sampler_t object 80: */ 81: void (*destroy)(bliss_sampler_t *this); 82: }; 83: 84: /** 85: * Create a bliss_sampler_t object. 86: * 87: * @param alg XOF to be used for the internal bitspender 88: * @param seed Seed used to initialize the internal bitspender 89: * @param set BLISS parameter set to be used 90: */ 91: bliss_sampler_t *bliss_sampler_create(ext_out_function_t alg, chunk_t seed, 92: const bliss_param_set_t *set); 93: 94: #endif /** BLISS_SAMPLER_H_ @}*/