mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-18 12:20:58 +01:00
changed key format, now includes the ed25519 pubkey for signing.
This commit is contained in:
@@ -27,7 +27,7 @@ int pcp_ed_verify(unsigned char *input, size_t inputlen, pcp_sig_t *sig, pcp_pub
|
||||
unsigned char *check = ucmalloc(crypto_hash_sha256_BYTES); // from file
|
||||
size_t mlen = 0;
|
||||
|
||||
if(crypto_sign_open(hash, &mlen, sig->edsig, crypto_hash_sha256_BYTES + crypto_sign_BYTES, p->public) != 0) {
|
||||
if(crypto_sign_open(hash, &mlen, sig->edsig, crypto_hash_sha256_BYTES + crypto_sign_BYTES, p->edpub) != 0) {
|
||||
fatal("Failed to open the signature using the public key 0x%s!\n", p->id);
|
||||
goto errve1;
|
||||
}
|
||||
@@ -50,13 +50,18 @@ int pcp_ed_verify(unsigned char *input, size_t inputlen, pcp_sig_t *sig, pcp_pub
|
||||
}
|
||||
|
||||
pcp_sig_t *pcp_ed_sign(unsigned char *message, size_t messagesize, pcp_key_t *s) {
|
||||
byte edpub[32] = { 0 };
|
||||
byte edsec[64] = { 0 };
|
||||
|
||||
crypto_sign_seed_keypair(edpub, edsec, s->secret);
|
||||
|
||||
unsigned char *hash = ucmalloc(crypto_hash_sha256_BYTES);
|
||||
size_t slen = crypto_hash_sha256_BYTES + crypto_sign_BYTES;
|
||||
unsigned char *signature = ucmalloc(slen);
|
||||
|
||||
crypto_hash_sha256(hash, message, messagesize);
|
||||
|
||||
crypto_sign(signature, &slen, hash, crypto_hash_sha256_BYTES, s->secret);
|
||||
crypto_sign(signature, &slen, hash, crypto_hash_sha256_BYTES, edsec);
|
||||
|
||||
pcp_sig_t *sig = pcp_ed_newsig(signature, s->id);
|
||||
|
||||
|
||||
14
libpcp/key.c
14
libpcp/key.c
@@ -69,6 +69,9 @@ char *pcp_getkeyid(pcp_key_t *k) {
|
||||
pcp_key_t * pcpkey_new () {
|
||||
byte public[32] = { 0 };
|
||||
byte secret[32] = { 0 };
|
||||
byte edpub[32] = { 0 };
|
||||
byte edsec[64] = { 0 };
|
||||
|
||||
|
||||
// generate curve 25519 keypair
|
||||
if(crypto_box_keypair (public, secret) != 0) {
|
||||
@@ -76,11 +79,15 @@ pcp_key_t * pcpkey_new () {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// generate ed25519 keypair from box secret
|
||||
crypto_sign_seed_keypair(edpub, edsec, secret);
|
||||
|
||||
// fill in our struct
|
||||
pcp_key_t *key = urmalloc(sizeof(pcp_key_t));
|
||||
memcpy (key->public, public, 32);
|
||||
memcpy (key->secret, secret, 32);
|
||||
memcpy (key->id, pcp_getkeyid(key), 17);
|
||||
memcpy (key->edpub, edpub, 32);
|
||||
|
||||
key->ctime = (long)time(0);
|
||||
|
||||
@@ -154,6 +161,7 @@ pcp_pubkey_t *pcpkey_pub_from_secret(pcp_key_t *key) {
|
||||
//pcp_dumpkey(key);
|
||||
pcp_pubkey_t *pub = urmalloc(sizeof (pcp_pubkey_t));
|
||||
memcpy(pub->public, key->public, 32);
|
||||
memcpy(pub->edpub, key->edpub, 32);
|
||||
memcpy(pub->owner, key->owner, 255);
|
||||
memcpy(pub->mail, key->mail, 255);
|
||||
memcpy(pub->id, key->id, 17);
|
||||
@@ -254,6 +262,8 @@ pcp_pubkey_t *pubkey2native(pcp_pubkey_t *k) {
|
||||
}
|
||||
|
||||
pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs) {
|
||||
byte edpub[32] = { 0 };
|
||||
byte edsec[64] = { 0 };
|
||||
size_t thlen = strnlen(theirs, 255);
|
||||
size_t inlen = 32 + thlen;
|
||||
unsigned char *both = ucmalloc(inlen);
|
||||
@@ -288,9 +298,13 @@ pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs) {
|
||||
// calculate pub from secret
|
||||
crypto_scalarmult_curve25519_base(tmp->public, tmp->secret);
|
||||
|
||||
// generate ed25519 keypair from box secret
|
||||
crypto_sign_seed_keypair(edpub, edsec, tmp->secret);
|
||||
|
||||
memcpy(tmp->owner, ours->owner, 255);
|
||||
memcpy(tmp->mail, ours->mail, 255);
|
||||
memcpy(tmp->id, pcp_getkeyid(tmp), 17);
|
||||
memcpy(tmp->edpub, edpub, 32);
|
||||
|
||||
memset(both, 0, inlen);
|
||||
memset(xor, 0, crypto_secretbox_KEYBYTES);
|
||||
|
||||
Reference in New Issue
Block a user