Add API to generate public key from private key

This commit is contained in:
Jeremy Lakeman 2013-07-25 14:40:59 +09:30
parent f1139d4c0e
commit 422671c906
4 changed files with 27 additions and 16 deletions

View File

@ -1,3 +1,5 @@
#include "crypto_sign_edwards25519sha512batch.h"
#include "nacl/src/crypto_sign_edwards25519sha512batch_ref/ge.h"
#include "serval.h"
#include "overlay_address.h"
#include "crypto.h"
@ -95,3 +97,21 @@ int crypto_sign_message(struct subscriber *source, unsigned char *content, int b
*content_len+=sig_length;
return ret;
}
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk)
{
IN();
unsigned char h[64];
ge_p3 A;
crypto_hash_sha512(h,skin,32);
h[0] &= 248;
h[31] &= 63;
h[31] |= 64;
ge_scalarmult_base(&A,h);
ge_p3_tobytes(pk,&A);
RETURN(0);
OUT();
}

View File

@ -13,5 +13,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 subscriber *source, unsigned char *content, int buffer_len, int *content_len);
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk);
#endif

View File

@ -226,7 +226,6 @@ int rhizome_manifest_bind_id(rhizome_manifest *m_in)
manifests on receiver nodes works easily. We might implement something that strips the id
variable out of the manifest when sending it, or some other scheme to avoid sending all the
extra bytes. */
rhizome_manifest_set(m_in, "id", alloca_tohex_bid(m_in->cryptoSignPublic));
if (!is_sid_any(m_in->author)) {
/* Set the BK using the provided authorship information.
Serval Security Framework defines BK as being:

View File

@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "conf.h"
#include "str.h"
#include "rhizome.h"
#include "crypto.h"
#include <stdlib.h>
#include <ctype.h>
@ -38,9 +39,10 @@ unsigned char *rhizome_bundle_shared_secret(rhizome_manifest *m)
int rhizome_manifest_createid(rhizome_manifest *m)
{
m->haveSecret=NEW_BUNDLE_ID;
int r=crypto_sign_edwards25519sha512batch_keypair(m->cryptoSignPublic,m->cryptoSignSecret);
if (!r) return 0;
return WHY("Failed to create keypair for manifest ID.");
if (crypto_sign_edwards25519sha512batch_keypair(m->cryptoSignPublic,m->cryptoSignSecret))
return WHY("Failed to create keypair for manifest ID.");
rhizome_manifest_set(m, "id", alloca_tohex_bid(m->cryptoSignPublic));
return 0;
}
/* Given a Rhizome Secret (RS) and bundle ID (BID), XOR a bundle key 'bkin' (private or public) with
@ -357,20 +359,9 @@ int rhizome_verify_bundle_privatekey(rhizome_manifest *m,
const unsigned char *pkin)
{
IN();
unsigned char h[64];
unsigned char pk[32];
ge_p3 A;
int i;
crypto_hash_sha512(h,sk,32);
h[0] &= 248;
h[31] &= 63;
h[31] |= 64;
ge_scalarmult_base(&A,h);
ge_p3_tobytes(pk,&A);
crypto_sign_compute_public_key(sk,pk);
for (i = 0;i < 32;++i)
if (pkin[i] != pk[i]) {
if (m&&sk==m->cryptoSignSecret&&pkin==m->cryptoSignPublic)