|
@ -23,7 +23,7 @@ |
|
|
#include "../pnacl_main.h" |
|
|
#include "../pnacl_main.h" |
|
|
#include "iguana777.h" |
|
|
#include "iguana777.h" |
|
|
#include "SuperNET.h" |
|
|
#include "SuperNET.h" |
|
|
|
|
|
#include <stdio.h> |
|
|
// ALL globals must be here!
|
|
|
// ALL globals must be here!
|
|
|
char *Iguana_validcommands[] = |
|
|
char *Iguana_validcommands[] = |
|
|
{ |
|
|
{ |
|
@ -527,15 +527,10 @@ extern gfshare_rand_func_t gfshare_fill_rand; |
|
|
/* ------------------------------------------------------[ Preparation ]---- */ |
|
|
/* ------------------------------------------------------[ Preparation ]---- */ |
|
|
|
|
|
|
|
|
/* Initialise a gfshare context for producing shares */ |
|
|
/* Initialise a gfshare context for producing shares */ |
|
|
gfshare_ctx* gfshare_ctx_init_enc(uint8_t* /* sharenrs */, |
|
|
gfshare_ctx* gfshare_ctx_init_enc(uint8_t* /* sharenrs */,unsigned int /* sharecount */, uint8_t /* threshold */,unsigned int /* size */); |
|
|
unsigned int /* sharecount */, |
|
|
|
|
|
uint8_t /* threshold */, |
|
|
|
|
|
unsigned int /* size */); |
|
|
|
|
|
|
|
|
|
|
|
/* Initialise a gfshare context for recombining shares */ |
|
|
/* Initialise a gfshare context for recombining shares */ |
|
|
gfshare_ctx* gfshare_ctx_init_dec(uint8_t* /* sharenrs */, |
|
|
gfshare_ctx* gfshare_ctx_init_dec(uint8_t* /* sharenrs */,unsigned int /* sharecount */,unsigned int /* size */); |
|
|
unsigned int /* sharecount */, |
|
|
|
|
|
unsigned int /* size */); |
|
|
|
|
|
|
|
|
|
|
|
/* Free a share context's memory. */ |
|
|
/* Free a share context's memory. */ |
|
|
void gfshare_ctx_free(gfshare_ctx* /* ctx */); |
|
|
void gfshare_ctx_free(gfshare_ctx* /* ctx */); |
|
@ -543,35 +538,28 @@ void gfshare_ctx_free(gfshare_ctx* /* ctx */); |
|
|
/* --------------------------------------------------------[ Splitting ]---- */ |
|
|
/* --------------------------------------------------------[ Splitting ]---- */ |
|
|
|
|
|
|
|
|
/* Provide a secret to the encoder. (this re-scrambles the coefficients) */ |
|
|
/* Provide a secret to the encoder. (this re-scrambles the coefficients) */ |
|
|
void gfshare_ctx_enc_setsecret(gfshare_ctx* /* ctx */, |
|
|
void gfshare_ctx_enc_setsecret(gfshare_ctx* /* ctx */,uint8_t* /* secret */); |
|
|
uint8_t* /* secret */); |
|
|
|
|
|
|
|
|
|
|
|
/* Extract a share from the context.
|
|
|
/* Extract a share from the context.
|
|
|
* 'share' must be preallocated and at least 'size' bytes long. |
|
|
* 'share' must be preallocated and at least 'size' bytes long. |
|
|
* 'sharenr' is the index into the 'sharenrs' array of the share you want. |
|
|
* 'sharenr' is the index into the 'sharenrs' array of the share you want. |
|
|
*/ |
|
|
*/ |
|
|
void gfshare_ctx_enc_getshare(gfshare_ctx* /* ctx */, |
|
|
void gfshare_ctx_enc_getshare(gfshare_ctx* /* ctx */,uint8_t /* sharenr */,uint8_t* /* share */); |
|
|
uint8_t /* sharenr */, |
|
|
|
|
|
uint8_t* /* share */); |
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------[ Recombination ]---- */ |
|
|
/* ----------------------------------------------------[ Recombination ]---- */ |
|
|
|
|
|
|
|
|
/* Inform a recombination context of a change in share indexes */ |
|
|
/* Inform a recombination context of a change in share indexes */ |
|
|
void gfshare_ctx_dec_newshares(gfshare_ctx* /* ctx */, |
|
|
void gfshare_ctx_dec_newshares(gfshare_ctx* /* ctx */, uint8_t* /* sharenrs */); |
|
|
uint8_t* /* sharenrs */); |
|
|
|
|
|
|
|
|
|
|
|
/* Provide a share context with one of the shares.
|
|
|
/* Provide a share context with one of the shares.
|
|
|
* The 'sharenr' is the index into the 'sharenrs' array |
|
|
* The 'sharenr' is the index into the 'sharenrs' array |
|
|
*/ |
|
|
*/ |
|
|
void gfshare_ctx_dec_giveshare(gfshare_ctx* /* ctx */, |
|
|
void gfshare_ctx_dec_giveshare(gfshare_ctx* /* ctx */,uint8_t /* sharenr */,uint8_t* /* share */); |
|
|
uint8_t /* sharenr */, |
|
|
|
|
|
uint8_t* /* share */); |
|
|
|
|
|
|
|
|
|
|
|
/* Extract the secret by interpolation of the shares.
|
|
|
/* Extract the secret by interpolation of the shares.
|
|
|
* secretbuf must be allocated and at least 'size' bytes long |
|
|
* secretbuf must be allocated and at least 'size' bytes long |
|
|
*/ |
|
|
*/ |
|
|
void gfshare_ctx_dec_extract(gfshare_ctx* /* ctx */, |
|
|
void gfshare_ctx_dec_extract(gfshare_ctx* /* ctx */,uint8_t* /* secretbuf */); |
|
|
uint8_t* /* secretbuf */); |
|
|
|
|
|
|
|
|
|
|
|
#endif /* LIBGFSHARE_H */ |
|
|
#endif /* LIBGFSHARE_H */ |
|
|
|
|
|
|
|
@ -592,9 +580,7 @@ struct _gfshare_ctx { |
|
|
unsigned int buffersize; |
|
|
unsigned int buffersize; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
static void |
|
|
static void _gfshare_fill_rand_using_random( uint8_t* buffer,unsigned int count ) |
|
|
_gfshare_fill_rand_using_random( uint8_t* buffer, |
|
|
|
|
|
unsigned int count ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
OS_randombytes(buffer,count); |
|
|
OS_randombytes(buffer,count); |
|
|
/*unsigned int i;
|
|
|
/*unsigned int i;
|
|
@ -609,11 +595,7 @@ gfshare_rand_func_t gfshare_fill_rand = NULL; |
|
|
|
|
|
|
|
|
/* ------------------------------------------------------[ Preparation ]---- */ |
|
|
/* ------------------------------------------------------[ Preparation ]---- */ |
|
|
|
|
|
|
|
|
static gfshare_ctx * |
|
|
static gfshare_ctx * _gfshare_ctx_init_core( uint8_t *sharenrs,unsigned int sharecount,uint8_t threshold,unsigned int size ) |
|
|
_gfshare_ctx_init_core( uint8_t *sharenrs, |
|
|
|
|
|
unsigned int sharecount, |
|
|
|
|
|
uint8_t threshold, |
|
|
|
|
|
unsigned int size ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
gfshare_ctx *ctx; |
|
|
gfshare_ctx *ctx; |
|
|
|
|
|
|
|
@ -649,11 +631,7 @@ _gfshare_ctx_init_core( uint8_t *sharenrs, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Initialise a gfshare context for producing shares */ |
|
|
/* Initialise a gfshare context for producing shares */ |
|
|
gfshare_ctx * |
|
|
gfshare_ctx * gfshare_ctx_init_enc( uint8_t* sharenrs,unsigned int sharecount,uint8_t threshold,unsigned int size ) |
|
|
gfshare_ctx_init_enc( uint8_t* sharenrs, |
|
|
|
|
|
unsigned int sharecount, |
|
|
|
|
|
uint8_t threshold, |
|
|
|
|
|
unsigned int size ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
unsigned int i; |
|
|
unsigned int i; |
|
|
|
|
|
|
|
@ -671,10 +649,7 @@ gfshare_ctx_init_enc( uint8_t* sharenrs, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Initialise a gfshare context for recombining shares */ |
|
|
/* Initialise a gfshare context for recombining shares */ |
|
|
gfshare_ctx* |
|
|
gfshare_ctx* gfshare_ctx_init_dec( uint8_t* sharenrs,unsigned int sharecount,unsigned int size ) |
|
|
gfshare_ctx_init_dec( uint8_t* sharenrs, |
|
|
|
|
|
unsigned int sharecount, |
|
|
|
|
|
unsigned int size ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
gfshare_ctx *ctx = _gfshare_ctx_init_core( sharenrs, sharecount, sharecount, size ); |
|
|
gfshare_ctx *ctx = _gfshare_ctx_init_core( sharenrs, sharecount, sharecount, size ); |
|
|
|
|
|
|
|
@ -685,8 +660,7 @@ gfshare_ctx_init_dec( uint8_t* sharenrs, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* Free a share context's memory. */ |
|
|
/* Free a share context's memory. */ |
|
|
void |
|
|
void gfshare_ctx_free( gfshare_ctx* ctx ) |
|
|
gfshare_ctx_free( gfshare_ctx* ctx ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
gfshare_fill_rand( ctx->buffer, ctx->buffersize ); |
|
|
gfshare_fill_rand( ctx->buffer, ctx->buffersize ); |
|
|
gfshare_fill_rand( ctx->sharenrs, ctx->sharecount ); |
|
|
gfshare_fill_rand( ctx->sharenrs, ctx->sharecount ); |
|
@ -699,9 +673,7 @@ gfshare_ctx_free( gfshare_ctx* ctx ) |
|
|
/* --------------------------------------------------------[ Splitting ]---- */ |
|
|
/* --------------------------------------------------------[ Splitting ]---- */ |
|
|
|
|
|
|
|
|
/* Provide a secret to the encoder. (this re-scrambles the coefficients) */ |
|
|
/* Provide a secret to the encoder. (this re-scrambles the coefficients) */ |
|
|
void |
|
|
void gfshare_ctx_enc_setsecret( gfshare_ctx* ctx,uint8_t* secret) |
|
|
gfshare_ctx_enc_setsecret( gfshare_ctx* ctx, |
|
|
|
|
|
uint8_t* secret) |
|
|
|
|
|
{ |
|
|
{ |
|
|
memcpy( ctx->buffer + ((ctx->threshold-1) * ctx->size), |
|
|
memcpy( ctx->buffer + ((ctx->threshold-1) * ctx->size), |
|
|
secret, |
|
|
secret, |
|
@ -713,10 +685,7 @@ gfshare_ctx_enc_setsecret( gfshare_ctx* ctx, |
|
|
* 'share' must be preallocated and at least 'size' bytes long. |
|
|
* 'share' must be preallocated and at least 'size' bytes long. |
|
|
* 'sharenr' is the index into the 'sharenrs' array of the share you want. |
|
|
* 'sharenr' is the index into the 'sharenrs' array of the share you want. |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void gfshare_ctx_enc_getshare( gfshare_ctx* ctx,uint8_t sharenr,uint8_t* share) |
|
|
gfshare_ctx_enc_getshare( gfshare_ctx* ctx, |
|
|
|
|
|
uint8_t sharenr, |
|
|
|
|
|
uint8_t* share) |
|
|
|
|
|
{ |
|
|
{ |
|
|
unsigned int pos, coefficient; |
|
|
unsigned int pos, coefficient; |
|
|
unsigned int ilog = logs[ctx->sharenrs[sharenr]]; |
|
|
unsigned int ilog = logs[ctx->sharenrs[sharenr]]; |
|
@ -738,9 +707,7 @@ gfshare_ctx_enc_getshare( gfshare_ctx* ctx, |
|
|
/* ----------------------------------------------------[ Recombination ]---- */ |
|
|
/* ----------------------------------------------------[ Recombination ]---- */ |
|
|
|
|
|
|
|
|
/* Inform a recombination context of a change in share indexes */ |
|
|
/* Inform a recombination context of a change in share indexes */ |
|
|
void |
|
|
void gfshare_ctx_dec_newshares( gfshare_ctx* ctx,uint8_t* sharenrs) |
|
|
gfshare_ctx_dec_newshares( gfshare_ctx* ctx, |
|
|
|
|
|
uint8_t* sharenrs) |
|
|
|
|
|
{ |
|
|
{ |
|
|
memcpy( ctx->sharenrs, sharenrs, ctx->sharecount ); |
|
|
memcpy( ctx->sharenrs, sharenrs, ctx->sharecount ); |
|
|
} |
|
|
} |
|
@ -748,10 +715,7 @@ gfshare_ctx_dec_newshares( gfshare_ctx* ctx, |
|
|
/* Provide a share context with one of the shares.
|
|
|
/* Provide a share context with one of the shares.
|
|
|
* The 'sharenr' is the index into the 'sharenrs' array |
|
|
* The 'sharenr' is the index into the 'sharenrs' array |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void gfshare_ctx_dec_giveshare( gfshare_ctx* ctx,uint8_t sharenr,uint8_t* share ) |
|
|
gfshare_ctx_dec_giveshare( gfshare_ctx* ctx, |
|
|
|
|
|
uint8_t sharenr, |
|
|
|
|
|
uint8_t* share ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
memcpy( ctx->buffer + (sharenr * ctx->size), share, ctx->size ); |
|
|
memcpy( ctx->buffer + (sharenr * ctx->size), share, ctx->size ); |
|
|
} |
|
|
} |
|
@ -759,9 +723,7 @@ gfshare_ctx_dec_giveshare( gfshare_ctx* ctx, |
|
|
/* Extract the secret by interpolation of the shares.
|
|
|
/* Extract the secret by interpolation of the shares.
|
|
|
* secretbuf must be allocated and at least 'size' bytes long |
|
|
* secretbuf must be allocated and at least 'size' bytes long |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void gfshare_ctx_dec_extract( gfshare_ctx* ctx,uint8_t* secretbuf ) |
|
|
gfshare_ctx_dec_extract( gfshare_ctx* ctx, |
|
|
|
|
|
uint8_t* secretbuf ) |
|
|
|
|
|
{ |
|
|
{ |
|
|
unsigned int i, j; |
|
|
unsigned int i, j; |
|
|
uint8_t *secret_ptr, *share_ptr, sharei,sharej; |
|
|
uint8_t *secret_ptr, *share_ptr, sharei,sharej; |
|
@ -839,7 +801,7 @@ void calc_shares(uint8_t *shares,uint8_t *secret,int32_t size,int32_t width,int3 |
|
|
free(buffer); |
|
|
free(buffer); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
//#include <stdio.h>
|
|
|
|
|
|
|
|
|
int32_t test(int32_t M,int32_t N,int32_t datasize) |
|
|
int32_t test(int32_t M,int32_t N,int32_t datasize) |
|
|
{ |
|
|
{ |
|
@ -967,8 +929,7 @@ int32_t init_sharenrs(uint8_t sharenrs[255],uint8_t *orig,int32_t m,int32_t n) |
|
|
|
|
|
|
|
|
/* Construct and write out the tables for the gfshare code */ |
|
|
/* Construct and write out the tables for the gfshare code */ |
|
|
|
|
|
|
|
|
int |
|
|
int maingen(int argc, char** argv) |
|
|
maingen(int argc, char** argv) |
|
|
|
|
|
{ |
|
|
{ |
|
|
uint8_t logs[256]; |
|
|
uint8_t logs[256]; |
|
|
uint8_t exps[255]; |
|
|
uint8_t exps[255]; |
|
|