crypto_sign_compute_public_key() return void not int

It can never fail, so no need to check return value for -1
This commit is contained in:
Andrew Bettison 2015-03-23 17:31:06 +10:30
parent 655b94eb3c
commit 5b7cfb8afb
5 changed files with 11 additions and 22 deletions

View File

@ -121,7 +121,7 @@ int crypto_sign_message(struct keyring_identity *identity, unsigned char *conten
return ret;
}
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk)
void crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk)
{
IN();
unsigned char h[64];
@ -135,6 +135,5 @@ int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk)
ge_scalarmult_base(&A,h);
ge_p3_tobytes(pk,&A);
RETURN(0);
OUT();
}

View File

@ -32,6 +32,6 @@ int crypto_create_signature(unsigned char *key,
unsigned char *content, int content_len,
unsigned char *signature, int *sig_length);
int crypto_sign_message(struct keyring_identity *identity, unsigned char *content, size_t buffer_len, size_t *content_len);
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk);
void crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk);
#endif

View File

@ -216,10 +216,7 @@ const char * rhizome_bundle_add_file(int appending,
goto error;
}
} else {
if (rhizome_new_bundle_from_secret(new_manifest, bsk) == -1) {
WHY(reason = "Failed to create bundle from given secret");
goto error;
}
rhizome_new_bundle_from_secret(new_manifest, bsk);
}
}
// TODO: one day there will be no default service, but for now if no service

View File

@ -371,7 +371,7 @@ void rhizome_vacuum_db(sqlite_retry_state *retry);
int rhizome_manifest_createid(rhizome_manifest *m);
int rhizome_get_bundle_from_seed(rhizome_manifest *m, const char *seed);
int rhizome_get_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk);
int rhizome_new_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk);
void rhizome_new_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk);
struct rhizome_manifest_summary {
rhizome_bid_t bid;

View File

@ -47,16 +47,14 @@ struct signing_key {
};
/* generate a keypair from a given secret key */
static int generate_keypair_from_secret(const rhizome_bk_t *bsk, struct signing_key *key)
static void generate_keypair_from_secret(const rhizome_bk_t *bsk, struct signing_key *key)
{
bcopy(bsk->binary, key->Private, sizeof bsk->binary); // first 32 bytes
if (crypto_sign_compute_public_key(key->Private, key->Public.binary) == -1)
return WHY("Could not generate public key");
crypto_sign_compute_public_key(key->Private, key->Public.binary);
// The last 32 bytes of the private key should be identical to the public key. This is what
// crypto_sign_edwards25519sha512batch_keypair() returns, and there is code that depends on it.
// TODO: Refactor the Rhizome private/public keypair to eliminate this duplication.
bcopy(key->Public.binary, key->Private + RHIZOME_BUNDLE_KEY_BYTES, sizeof key->Public.binary);
return 0;
}
/* Generate a new empty manifest from the given keypair.
@ -90,8 +88,7 @@ int rhizome_get_bundle_from_seed(rhizome_manifest *m, const char *seed)
int rhizome_get_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
{
struct signing_key key;
if (generate_keypair_from_secret(bsk, &key))
return -1;
generate_keypair_from_secret(bsk, &key);
switch (rhizome_retrieve_manifest(&key.Public, m)) {
case RHIZOME_BUNDLE_STATUS_NEW:
rhizome_new_bundle_from_keypair(m, &key);
@ -109,13 +106,11 @@ int rhizome_get_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
/* Generate a bundle id deterministically from the given bundle secret key.
* Then initialise a new empty manifest.
*/
int rhizome_new_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
void rhizome_new_bundle_from_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
{
struct signing_key key;
if (generate_keypair_from_secret(bsk, &key))
return -1;
generate_keypair_from_secret(bsk, &key);
rhizome_new_bundle_from_keypair(m, &key);
return 0;
}
/* Given a Rhizome Secret (RS) and bundle ID (BID), XOR a bundle key 'bkin' (private or public) with
@ -446,10 +441,8 @@ int rhizome_verify_bundle_privatekey(const unsigned char *sk, const unsigned cha
{
IN();
rhizome_bid_t pk;
if (crypto_sign_compute_public_key(sk, pk.binary) == -1)
RETURN(0);
int ret = bcmp(pkin, pk.binary, sizeof pk.binary) == 0;
RETURN(ret);
crypto_sign_compute_public_key(sk, pk.binary);
RETURN(bcmp(pkin, pk.binary, sizeof pk.binary) == 0);
}
int rhizome_sign_hash(rhizome_manifest *m, rhizome_signature *out)