refactor out code that calculates public key from a crypto sign public

key, e.g., to calculate a BID from a private key.
This commit is contained in:
gardners 2013-05-14 11:55:32 +09:30
parent 7aaaece42c
commit 98d7e07058
3 changed files with 51 additions and 15 deletions

View File

@ -1,3 +1,25 @@
/*
Serval Distributed Numbering Architecture (DNA)
Copyright (C) 2010-2013 Paul Gardner-Stephen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#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 +117,24 @@ int crypto_sign_message(struct subscriber *source, unsigned char *content, int b
*content_len+=sig_length;
return ret;
}
int _crypto_sign_compute_public_key(struct __sourceloc __whence,
const unsigned char *skin,
const 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((unsigned char *)pk,&A);
RETURN(0);
OUT();
}

View File

@ -17,9 +17,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "crypto_sign_edwards25519sha512batch.h"
#include "nacl/src/crypto_sign_edwards25519sha512batch_ref/ge.h"
#include "serval.h"
#include "conf.h"
#include "str.h"
@ -358,19 +355,10 @@ int rhizome_verify_bundle_privatekey(rhizome_manifest *m,
{
IN();
unsigned char h[64];
unsigned char pk[32];
ge_p3 A;
unsigned char pk[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
if (crypto_sign_compute_public_key(sk,pk)) RETURN(-1);
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);
for (i = 0;i < 32;++i)
if (pkin[i] != pk[i]) {
if (m&&sk==m->cryptoSignSecret&&pkin==m->cryptoSignPublic)

View File

@ -842,4 +842,9 @@ int link_state_announce_links();
int generate_nonce(unsigned char *nonce,int bytes);
int _crypto_sign_compute_public_key(struct __sourceloc __whence,
const unsigned char *skin,
const unsigned char *pk);
#define crypto_sign_compute_public_key(skin,pk) _crypto_sign_compute_public_key(__WHENCE__,skin,pk)
#endif // __SERVALD_SERVALD_H