yarrow: trim trailing spaces
This commit is contained in:
parent
2cd666f284
commit
9c4fc762fc
@ -13,7 +13,7 @@
|
|||||||
/**
|
/**
|
||||||
@file yarrow.c
|
@file yarrow.c
|
||||||
Yarrow PRNG, Tom St Denis
|
Yarrow PRNG, Tom St Denis
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef LTC_YARROW
|
#ifdef LTC_YARROW
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ const struct ltc_prng_descriptor yarrow_desc =
|
|||||||
Start the PRNG
|
Start the PRNG
|
||||||
@param prng [out] The PRNG state to initialize
|
@param prng [out] The PRNG state to initialize
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_start(prng_state *prng)
|
int yarrow_start(prng_state *prng)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
LTC_ARGCHK(prng != NULL);
|
LTC_ARGCHK(prng != NULL);
|
||||||
|
|
||||||
/* these are the default hash/cipher combo used */
|
/* these are the default hash/cipher combo used */
|
||||||
@ -64,13 +64,13 @@ int yarrow_start(prng_state *prng)
|
|||||||
prng->yarrow.cipher = register_cipher(&saferp_desc);
|
prng->yarrow.cipher = register_cipher(&saferp_desc);
|
||||||
#elif defined(LTC_RC2)
|
#elif defined(LTC_RC2)
|
||||||
prng->yarrow.cipher = register_cipher(&rc2_desc);
|
prng->yarrow.cipher = register_cipher(&rc2_desc);
|
||||||
#elif defined(LTC_NOEKEON)
|
#elif defined(LTC_NOEKEON)
|
||||||
prng->yarrow.cipher = register_cipher(&noekeon_desc);
|
prng->yarrow.cipher = register_cipher(&noekeon_desc);
|
||||||
#elif defined(LTC_ANUBIS)
|
#elif defined(LTC_ANUBIS)
|
||||||
prng->yarrow.cipher = register_cipher(&anubis_desc);
|
prng->yarrow.cipher = register_cipher(&anubis_desc);
|
||||||
#elif defined(LTC_KSEED)
|
#elif defined(LTC_KSEED)
|
||||||
prng->yarrow.cipher = register_cipher(&kseed_desc);
|
prng->yarrow.cipher = register_cipher(&kseed_desc);
|
||||||
#elif defined(LTC_KHAZAD)
|
#elif defined(LTC_KHAZAD)
|
||||||
prng->yarrow.cipher = register_cipher(&khazad_desc);
|
prng->yarrow.cipher = register_cipher(&khazad_desc);
|
||||||
#elif defined(LTC_CAST5)
|
#elif defined(LTC_CAST5)
|
||||||
prng->yarrow.cipher = register_cipher(&cast5_desc);
|
prng->yarrow.cipher = register_cipher(&cast5_desc);
|
||||||
@ -131,7 +131,7 @@ int yarrow_start(prng_state *prng)
|
|||||||
@param inlen Length of the data to add
|
@param inlen Length of the data to add
|
||||||
@param prng PRNG state to update
|
@param prng PRNG state to update
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
|
int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
|
||||||
{
|
{
|
||||||
hash_state md;
|
hash_state md;
|
||||||
@ -139,9 +139,9 @@ int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state
|
|||||||
|
|
||||||
LTC_ARGCHK(in != NULL);
|
LTC_ARGCHK(in != NULL);
|
||||||
LTC_ARGCHK(prng != NULL);
|
LTC_ARGCHK(prng != NULL);
|
||||||
|
|
||||||
LTC_MUTEX_LOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_LOCK(&prng->yarrow.prng_lock);
|
||||||
|
|
||||||
if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
|
if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
@ -150,11 +150,11 @@ int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state
|
|||||||
/* start the hash */
|
/* start the hash */
|
||||||
if ((err = hash_descriptor[prng->yarrow.hash].init(&md)) != CRYPT_OK) {
|
if ((err = hash_descriptor[prng->yarrow.hash].init(&md)) != CRYPT_OK) {
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hash the current pool */
|
/* hash the current pool */
|
||||||
if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool,
|
if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool,
|
||||||
hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) {
|
hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) {
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
@ -180,7 +180,7 @@ int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state
|
|||||||
Make the PRNG ready to read from
|
Make the PRNG ready to read from
|
||||||
@param prng The PRNG to make active
|
@param prng The PRNG to make active
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_ready(prng_state *prng)
|
int yarrow_ready(prng_state *prng)
|
||||||
{
|
{
|
||||||
int ks, err;
|
int ks, err;
|
||||||
@ -192,7 +192,7 @@ int yarrow_ready(prng_state *prng)
|
|||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
|
if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
@ -224,7 +224,7 @@ int yarrow_ready(prng_state *prng)
|
|||||||
@param outlen Length of output
|
@param outlen Length of output
|
||||||
@param prng The active PRNG to read from
|
@param prng The active PRNG to read from
|
||||||
@return Number of octets read
|
@return Number of octets read
|
||||||
*/
|
*/
|
||||||
unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng)
|
unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng)
|
||||||
{
|
{
|
||||||
LTC_ARGCHK(out != NULL);
|
LTC_ARGCHK(out != NULL);
|
||||||
@ -234,7 +234,7 @@ unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *
|
|||||||
|
|
||||||
/* put out in predictable state first */
|
/* put out in predictable state first */
|
||||||
zeromem(out, outlen);
|
zeromem(out, outlen);
|
||||||
|
|
||||||
/* now randomize it */
|
/* now randomize it */
|
||||||
if (ctr_encrypt(out, out, outlen, &prng->yarrow.ctr) != CRYPT_OK) {
|
if (ctr_encrypt(out, out, outlen, &prng->yarrow.ctr) != CRYPT_OK) {
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
@ -248,7 +248,7 @@ unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *
|
|||||||
Terminate the PRNG
|
Terminate the PRNG
|
||||||
@param prng The PRNG to terminate
|
@param prng The PRNG to terminate
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_done(prng_state *prng)
|
int yarrow_done(prng_state *prng)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -260,7 +260,7 @@ int yarrow_done(prng_state *prng)
|
|||||||
|
|
||||||
/* we invented one */
|
/* we invented one */
|
||||||
err = ctr_done(&prng->yarrow.ctr);
|
err = ctr_done(&prng->yarrow.ctr);
|
||||||
|
|
||||||
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_UNLOCK(&prng->yarrow.prng_lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ int yarrow_done(prng_state *prng)
|
|||||||
@param outlen [in/out] Max size and resulting size of the state
|
@param outlen [in/out] Max size and resulting size of the state
|
||||||
@param prng The PRNG to export
|
@param prng The PRNG to export
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
||||||
{
|
{
|
||||||
LTC_ARGCHK(out != NULL);
|
LTC_ARGCHK(out != NULL);
|
||||||
@ -295,21 +295,21 @@ int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
|
|||||||
|
|
||||||
return CRYPT_OK;
|
return CRYPT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Import a PRNG state
|
Import a PRNG state
|
||||||
@param in The PRNG state
|
@param in The PRNG state
|
||||||
@param inlen Size of the state
|
@param inlen Size of the state
|
||||||
@param prng The PRNG to import
|
@param prng The PRNG to import
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
|
int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
LTC_ARGCHK(in != NULL);
|
LTC_ARGCHK(in != NULL);
|
||||||
LTC_ARGCHK(prng != NULL);
|
LTC_ARGCHK(prng != NULL);
|
||||||
|
|
||||||
LTC_MUTEX_LOCK(&prng->yarrow.prng_lock);
|
LTC_MUTEX_LOCK(&prng->yarrow.prng_lock);
|
||||||
|
|
||||||
if (inlen != 64) {
|
if (inlen != 64) {
|
||||||
@ -329,7 +329,7 @@ int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng
|
|||||||
/**
|
/**
|
||||||
PRNG self-test
|
PRNG self-test
|
||||||
@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
|
@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
|
||||||
*/
|
*/
|
||||||
int yarrow_test(void)
|
int yarrow_test(void)
|
||||||
{
|
{
|
||||||
#ifndef LTC_TEST
|
#ifndef LTC_TEST
|
||||||
@ -341,7 +341,7 @@ int yarrow_test(void)
|
|||||||
if ((err = yarrow_start(&prng)) != CRYPT_OK) {
|
if ((err = yarrow_start(&prng)) != CRYPT_OK) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now let's test the hash/cipher that was chosen */
|
/* now let's test the hash/cipher that was chosen */
|
||||||
if ((err = cipher_descriptor[prng.yarrow.cipher].test()) != CRYPT_OK) {
|
if ((err = cipher_descriptor[prng.yarrow.cipher].test()) != CRYPT_OK) {
|
||||||
return err;
|
return err;
|
||||||
|
Loading…
Reference in New Issue
Block a user