mgf1: Refactored MGF1 as an XOF

This commit is contained in:
Andreas Steffen
2016-09-21 06:40:52 +02:00
parent e9e643b240
commit 188b190a70
60 changed files with 966 additions and 644 deletions
@@ -23,7 +23,7 @@
#include "ntt_fft.h"
#include "ntt_fft_reduce.h"
#include <crypto/mgf1/mgf1_bitspender.h>
#include <crypto/xofs/xof_bitspender.h>
#include <asn1/asn1.h>
#include <asn1/asn1_parser.h>
#include <asn1/oid.h>
@@ -174,7 +174,8 @@ static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg,
bliss_sampler_t *sampler = NULL;
rng_t *rng;
hasher_t *hasher;
hash_algorithm_t mgf1_alg, oracle_alg;
hash_algorithm_t mgf1_alg;
ext_out_function_t oracle_alg;
size_t mgf1_seed_len;
uint8_t mgf1_seed_buf[HASH_SIZE_SHA512], data_hash_buf[HASH_SIZE_SHA512];
chunk_t mgf1_seed, data_hash;
@@ -226,7 +227,7 @@ static bool sign_bliss(private_bliss_private_key_t *this, hash_algorithm_t alg,
}
/* MGF1 hash algorithm to be used for random oracle */
oracle_alg = HASH_SHA512;
oracle_alg = XOF_MGF1_SHA512;
/* Initialize a couple of needed variables */
n = this->set->n;
@@ -834,14 +835,14 @@ static uint32_t invert(private_bliss_private_key_t *this, uint32_t x)
* Create a vector with sparse and small coefficients from seed
*/
static int8_t* create_vector_from_seed(private_bliss_private_key_t *this,
hash_algorithm_t alg, chunk_t seed)
ext_out_function_t alg, chunk_t seed)
{
mgf1_bitspender_t *bitspender;
xof_bitspender_t *bitspender;
uint32_t index, sign;
int8_t *vector;
int non_zero;
bitspender = mgf1_bitspender_create(alg, seed, FALSE);
bitspender = xof_bitspender_create(alg, seed, FALSE);
if (!bitspender)
{
return NULL;
@@ -910,7 +911,7 @@ static bool create_secret(private_bliss_private_key_t *this, rng_t *rng,
int i, n;
chunk_t seed;
size_t seed_len;
hash_algorithm_t alg;
ext_out_function_t alg;
n = this->set->n;
*s1 = NULL;
@@ -919,12 +920,12 @@ static bool create_secret(private_bliss_private_key_t *this, rng_t *rng,
/* Set MGF1 hash algorithm and seed length based on security strength */
if (this->set->strength > 160)
{
alg = HASH_SHA256;
alg = XOF_MGF1_SHA256;
seed_len = HASH_SIZE_SHA256;
}
else
{
alg = HASH_SHA1;
alg = XOF_MGF1_SHA1;
seed_len = HASH_SIZE_SHA1;
}
seed = chunk_create(seed_buf, seed_len);
@@ -76,7 +76,7 @@ static bool verify_bliss(private_bliss_public_key_t *this, hash_algorithm_t alg,
uint8_t data_hash_buf[HASH_SIZE_SHA512];
chunk_t data_hash;
hasher_t *hasher;
hash_algorithm_t oracle_alg;
ext_out_function_t oracle_alg;
ntt_fft_t *fft;
bliss_signature_t *sig;
bool success = FALSE;
@@ -110,7 +110,7 @@ static bool verify_bliss(private_bliss_public_key_t *this, hash_algorithm_t alg,
}
/* MGF1 hash algorithm to be used for random oracle */
oracle_alg = HASH_SHA512;
oracle_alg = XOF_MGF1_SHA512;
/* Initialize a couple of needed variables */
n = this->set->n;
@@ -17,7 +17,7 @@
typedef struct private_bliss_sampler_t private_bliss_sampler_t;
#include <crypto/mgf1/mgf1_bitspender.h>
#include <crypto/xofs/xof_bitspender.h>
/**
* Private data of a bliss_sampler_t object.
@@ -37,7 +37,7 @@ struct private_bliss_sampler_t {
/**
* Bitspender used for random rejection sampling
*/
mgf1_bitspender_t *bitspender;
xof_bitspender_t *bitspender;
};
@@ -222,13 +222,13 @@ METHOD(bliss_sampler_t, destroy, void,
/**
* See header.
*/
bliss_sampler_t *bliss_sampler_create(hash_algorithm_t alg, chunk_t seed,
bliss_sampler_t *bliss_sampler_create(ext_out_function_t alg, chunk_t seed,
const bliss_param_set_t *set)
{
private_bliss_sampler_t *this;
mgf1_bitspender_t *bitspender;
xof_bitspender_t *bitspender;
bitspender = mgf1_bitspender_create(alg, seed, FALSE);
bitspender = xof_bitspender_create(alg, seed, FALSE);
if (!bitspender)
{
return NULL;
@@ -84,11 +84,11 @@ struct bliss_sampler_t {
/**
* Create a bliss_sampler_t object.
*
* @param alg Hash algorithm to be used for the internal bitspender
* @param alg XOF to be used for the internal bitspender
* @param seed Seed used to initialize the internal bitspender
* @param set BLISS parameter set to be used
*/
bliss_sampler_t *bliss_sampler_create(hash_algorithm_t alg, chunk_t seed,
bliss_sampler_t *bliss_sampler_create(ext_out_function_t alg, chunk_t seed,
const bliss_param_set_t *set);
#endif /** BLISS_SAMPLER_H_ @}*/
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Andreas Steffen
* Copyright (C) 2014-2016 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -17,7 +17,7 @@
#include <asn1/asn1.h>
#include <crypto/hashers/hasher.h>
#include <crypto/mgf1/mgf1_bitspender.h>
#include <crypto/xofs/xof_bitspender.h>
#include <utils/debug.h>
/**
@@ -56,7 +56,7 @@ void bliss_utils_round_and_drop(const bliss_param_set_t *set,
/**
* See header.
*/
bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
bool bliss_utils_generate_c(ext_out_function_t alg, chunk_t data_hash,
uint16_t *ud, const bliss_param_set_t *set,
uint16_t *c_indices)
{
@@ -65,7 +65,7 @@ bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
uint32_t index;
uint8_t *seed_pos;
chunk_t seed;
mgf1_bitspender_t *bitspender;
xof_bitspender_t *bitspender;
seed = chunk_alloca(data_hash.len + set->n * sizeof(uint16_t));
@@ -80,7 +80,7 @@ bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
seed_pos += sizeof(uint16_t);
}
bitspender = mgf1_bitspender_create(alg, seed, FALSE);
bitspender = xof_bitspender_create(alg, seed, FALSE);
if (!bitspender)
{
return NULL;
+10 -10
View File
@@ -48,23 +48,23 @@ void bliss_utils_round_and_drop(const bliss_param_set_t *set,
/**
* Generate the binary challenge vector c as an array of kappa indices
*
* @param alg hash algorithm to be used for the internal oracle
* @param data_hash hash of the data to be signed
* @param ud input vector ud of size n
* @param set BLISS parameter set to be used (n, n_bits, kappa)
* @param c_indices indexes of non-zero challenge coefficients
* @param alg XOF to be used for the internal oracle
* @param data_hash hash of the data to be signed
* @param ud input vector ud of size n
* @param set BLISS parameter set to be used (n, n_bits, kappa)
* @param c_indices indexes of non-zero challenge coefficients
*/
bool bliss_utils_generate_c(hash_algorithm_t alg, chunk_t data_hash,
bool bliss_utils_generate_c(ext_out_function_t alg, chunk_t data_hash,
uint16_t *ud, const bliss_param_set_t *set,
uint16_t *c_indices);
/**
* Check the infinity and l2 norms of the vectors z1 and z2d << d
*
* @param set BLISS parameter set
* @param z1 input vector
* @param z2d input vector
* @result TRUE if infinite and l2 norms do not exceed boundaries
* @param set BLISS parameter set
* @param z1 input vector
* @param z2d input vector
* @result TRUE if infinite and l2 norms do not exceed boundaries
*/
bool bliss_utils_check_norms(const bliss_param_set_t *set,
int32_t *z1, int16_t *z2d);