logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

gfshare_ctx_init_enc, etc. - Shamir Secret Sharing

Author

Written by Daniel Silverstone.

Description

The gfshare_fill_rand variable must contain a pointer to a function which takes an unsignedchar* and an unsignedint and fills the given buffer with the given number of random bytes before calling any of the functions which create or populate contexts. If you cannot do this with a cryptographically secure mechanism then the library provides the gfshare_bad_idea_but_fill_rand_using_random value which you can put into gfshare_fill_rand and which will use the C library function random() to fill the buffer. You should ensure you call srandom() at least once before using any of the other functions though. The gfshare_ctx_init_enc() function returns a context object which can be used for encoding shares of a secret. The context encodes against sharecount shares which are numbered in the array sharenrs. The secret is always size bytes long and the resultant shares will need at least threshold of the shares present for recombination. It is critical that threshold be at least one lower than sharecount. The gfshare_ctx_init_dec() function returns a context object which can be used to recombine shares to recover a secret. Each share and the resulting secret will be size bytes long. The context can be used to recombine sharecount shares which are numbered in the sharenrs array. The gfshare_ctx_free() function frees all the memory associated with a gfshare context including the memory belonging to the context itself. The gfshare_ctx_enc_setsecret() function provides the secret you wish to encode to the context. The secret will be copied into the internal buffer of the library. The gfshare_ctx_enc_getshare() function extracts a particular share from the context. The share buffer must be preallocated to the size of the shares and the sharenr parameter is an index into the sharenrs array used to initialise the context The gfshare_ctx_dec_newshares() function informs the decode context of a change in the share numbers available to the context. The number of shares cannot be changed but the sharenrs can be zero to indicate that a particular share is missing currently. The gfshare_ctx_dec_giveshare() function provides the decode context with a given share. The share number itself was previously provided in a sharenrs array and the sharenr parameter is the index into that array of the number of the share being provided in the share memory block. The gfshare_ctx_dec_extract() function combines the provided shares to recalculate the secret. It is recommended that you mlock() the secretbuf before calling this function, so that the recombined secret will never be written to swap. This may help to prevent a malicious party discovering the content of your secret. You should also randomise the content of the buffer once you are finished using the recombined secret.

Errors

Any function which can fail for any reason will return NULL on error.

Name

gfshare_ctx_init_enc, etc. - Shamir Secret Sharing

Reporting Bugs

Report bugs against the libgfshare product on www.launchpad.net.

See Also

gfsplit(1), gfcombine(1), gfshare(7) 2.0.0 June 2015 LIBGFSHARE(5)

Synopsis

#include<libgfshare.h>gfshare_rand_func_tgfshare_fill_rand;gfshare_rand_func_tgfshare_bad_idea_but_fill_rand_using_random;gfshare_ctx*gfshare_ctx_init_enc(unsignedchar*sharenrs,unsignedintsharecount,unsignedcharthreshold,unsignedintsize);gfshare_ctx*gfshare_ctx_init_dec(unsignedchar*sharenrs,unsignedintsharecount,unsignedintsize);voidgfshare_ctx_free(gfshare_ctx*ctx);voidgfshare_ctx_enc_setsecret(gfshare_ctx*ctx,unsignedchar*secret);voidgfshare_ctx_enc_getshare(gfshare_ctx*ctx,unsignedcharsharenr,unsignedchar*share);voidgfshare_ctx_dec_newshares(gfshare_ctx*ctx,unsignedchar*sharenrs);voidgfshare_ctx_dec_giveshare(gfshare_ctx*ctx,unsignedcharsharenr,unsignedchar*share);voidgfshare_ctx_dec_extract(gfshare_ctx*ctx,unsignedchar*secretbuf);

See Also