renamed 'public' to 'pub' to avoid conflict with c++ api

This commit is contained in:
TLINDEN
2013-11-29 20:01:42 +01:00
parent 2fdbf8e1be
commit a9b2796af2
10 changed files with 165 additions and 162 deletions

View File

@@ -27,7 +27,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
size_t clearsize,
unsigned char *nonce,
unsigned char *secret,
unsigned char *public) {
unsigned char *pub) {
unsigned char *pad_clear;
unsigned char *pad_cipher;
@@ -39,7 +39,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
// crypto_box(c,m,mlen,n,pk,sk);
crypto_box(pad_cipher, pad_clear,
clearsize + crypto_box_ZEROBYTES, nonce, public, secret);
clearsize + crypto_box_ZEROBYTES, nonce, pub, secret);
pcp_pad_remove(cipher, pad_cipher, crypto_secretbox_BOXZEROBYTES, ciphersize);
@@ -54,7 +54,7 @@ size_t pcp_sodium_box(unsigned char **cipher,
int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
size_t messagesize, unsigned char *nonce,
unsigned char *secret, unsigned char *public) {
unsigned char *secret, unsigned char *pub) {
// verify/decrypt the box
unsigned char *pad_cipher;
unsigned char *pad_clear;
@@ -66,7 +66,7 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
// crypto_box_open(m,c,clen,n,pk,sk);
if (crypto_box_open(pad_clear, pad_cipher,
messagesize + crypto_box_BOXZEROBYTES,
nonce, public, secret) == 0) {
nonce, pub, secret) == 0) {
success = 0;
}
@@ -81,7 +81,7 @@ int pcp_sodium_verify_box(unsigned char **cleartext, unsigned char* message,
unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *public,
unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
unsigned char *message, size_t messagesize,
size_t *csize) {
@@ -90,7 +90,7 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *public,
unsigned char *cipher;
size_t es = pcp_sodium_box(&cipher, message, messagesize, nonce,
secret->secret, public->public);
secret->secret, pub->pub);
if(es <= messagesize) {
fatal("failed to encrypt message!\n");
@@ -98,7 +98,7 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *public,
}
// scip
//fprintf(stderr, "public: "); pcpprint_bin(stderr, public->public, 32); fprintf(stderr, "\n");
//fprintf(stderr, "public: "); pcpprint_bin(stderr, pub->pub, 32); fprintf(stderr, "\n");
//fprintf(stderr, "secret: "); pcpprint_bin(stderr, secret->secret, 32); fprintf(stderr, "\n");
//fprintf(stderr, "cipher: "); pcpprint_bin(stderr, cipher, es); fprintf(stderr, "\n");
//fprintf(stderr, " nonce: "); pcpprint_bin(stderr, nonce, crypto_secretbox_NONCEBYTES); fprintf(stderr, "\n");
@@ -124,7 +124,7 @@ unsigned char *pcp_box_encrypt(pcp_key_t *secret, pcp_pubkey_t *public,
}
unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *public,
unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *pub,
unsigned char *cipher, size_t ciphersize,
size_t *dsize) {
@@ -139,7 +139,7 @@ unsigned char *pcp_box_decrypt(pcp_key_t *secret, pcp_pubkey_t *public,
if(pcp_sodium_verify_box(&message, cipheronly,
ciphersize - crypto_secretbox_NONCEBYTES,
nonce, secret->secret, public->public) != 0){
nonce, secret->secret, pub->pub) != 0){
fatal("failed to decrypt message!\n");
goto errbed;
}

View File

@@ -59,7 +59,7 @@ unsigned char *pcp_derivekey(char *passphrase) {
char *pcp_getkeyid(pcp_key_t *k) {
uint32_t s, p;
p = jen_hash(k->public, 32, JEN_PSALT);
p = jen_hash(k->pub, 32, JEN_PSALT);
s = jen_hash(k->secret, 32, JEN_SSALT);
char *id = ucmalloc(17);
snprintf(id, 17, "%08X%08X", p, s);
@@ -98,18 +98,18 @@ void pcp_ed_keypairs(byte *csk, byte *esk) {
}
pcp_key_t * pcpkey_new () {
byte public[32] = { 0 };
byte pub[32] = { 0 };
byte secret[32] = { 0 };
byte edpub[32] = { 0 };
byte edsec[64] = { 0 };
byte *seed = urmalloc(32);
pcp_keypairs(secret, public, edsec, edpub, seed);
pcp_keypairs(secret, pub, edsec, edpub, seed);
// fill in our struct
pcp_key_t *key = urmalloc(sizeof(pcp_key_t));
memcpy (key->public, public, 32);
memcpy (key->pub, pub, 32);
memcpy (key->secret, secret, 32);
memcpy (key->edpub, edpub, 32);
memcpy (key->edsecret, edsec, 64);
@@ -192,7 +192,7 @@ pcp_key_t *pcpkey_decrypt(pcp_key_t *key, char *passphrase) {
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->pub, key->pub, 32);
memcpy(pub->edpub, key->edpub, 32);
memcpy(pub->owner, key->owner, 255);
memcpy(pub->mail, key->mail, 255);
@@ -205,24 +205,24 @@ pcp_pubkey_t *pcpkey_pub_from_secret(pcp_key_t *key) {
}
char *pcppubkey_get_art(pcp_pubkey_t *k) {
char *r = key_fingerprint_randomart(k->public, sizeof(k));
char *r = key_fingerprint_randomart(k->pub, sizeof(k));
return r;
}
char *pcpkey_get_art(pcp_key_t *k) {
char *r = key_fingerprint_randomart(k->public, sizeof(k));
char *r = key_fingerprint_randomart(k->pub, sizeof(k));
return r;
}
unsigned char *pcppubkey_getchecksum(pcp_pubkey_t *k) {
unsigned char *hash = ucmalloc(32);
crypto_hash_sha256(hash, k->public, 32);
crypto_hash_sha256(hash, k->pub, 32);
return hash;
}
unsigned char *pcpkey_getchecksum(pcp_key_t *k) {
unsigned char *hash = ucmalloc(32);
crypto_hash_sha256(hash, k->public, 32);
crypto_hash_sha256(hash, k->pub, 32);
return hash;
}
@@ -282,7 +282,7 @@ 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 };
byte public[32] = { 0 };
byte pub[32] = { 0 };
byte secret[32] = { 0 };
byte *seed = ucmalloc(32);
@@ -299,14 +299,14 @@ pcp_key_t *pcp_derive_pcpkey (pcp_key_t *ours, char *theirs) {
goto errdp1;
}
pcp_keypairs(secret, public, edsec, edpub, seed);
pcp_keypairs(secret, pub, edsec, edpub, seed);
pcp_key_t * tmp = pcpkey_new ();
memcpy(tmp->secret, secret, 32);
memcpy(tmp->edpub, edpub, 32);
memcpy(tmp->edsecret, edsec, 64);
memcpy(tmp->public, public, 32);
memcpy(tmp->pub, pub, 32);
memcpy(tmp->owner, ours->owner, 255);
memcpy(tmp->mail, ours->mail, 255);
@@ -347,3 +347,105 @@ void *pcp_keyblob(void *k, int type) {
}
return blob;
}
int pcp_sanitycheck_pub(pcp_pubkey_t *key) {
if(key->pub[0] == 0) {
fatal("Pubkey sanity check: public key contained in key seems to be empty!\n");
return 1;
}
if(key->type != PCP_KEY_TYPE_PUBLIC) {
fatal("Pubkey sanity check: key type is not PUBLIC (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_PUBLIC, key->type);
return 1;
}
if(key->version != PCP_KEY_VERSION) {
fatal("Pubkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version);
return 1;
}
if(key->serial <= 0) {
fatal("Pubkey sanity check: invalid serial number: %08X!\n", key->serial);
return 1;
}
if(key->id[16] != '\0') {
char *got = ucmalloc(17);
memcpy(got, key->id, 17);
got[16] = '\0';
fatal("Pubkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
free(got);
return 1;
}
struct tm *c;
time_t t = (time_t)key->ctime;
c = localtime(&t);
if(c->tm_year <= 0 || c->tm_year > 1100) {
// well, I'm perhaps overacting here :)
fatal("Pubkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
return 1;
}
pcp_pubkey_t *maybe = pcphash_pubkeyexists(key->id);
if(maybe != NULL) {
fatal("Pubkey sanity check: there already exists a key with the id 0x%s\n", key->id);
return 1;
}
return 0;
}
int pcp_sanitycheck_key(pcp_key_t *key) {
if(key->encrypted[0] == 0) {
fatal("Secretkey sanity check: secret key contained in key seems to be empty!\n");
return 1;
}
if(key->type != PCP_KEY_TYPE_SECRET && key->type != PCP_KEY_TYPE_MAINSECRET) {
fatal("Secretkey sanity check: key type is not SECRET (expected: %02x, got: %02x)!\n",
PCP_KEY_TYPE_SECRET, key->type);
return 1;
}
if(key->version != PCP_KEY_VERSION) {
fatal("Secretkey sanity check: unknown key version (expected: %08X, got: %08X)!\n",
PCP_KEY_VERSION, key->version);
return 1;
}
if(key->serial <= 0) {
fatal("Secretkey sanity check: invalid serial number: %08X!\n", key->serial);
return 1;
}
if(key->id[16] != '\0') {
char *got = ucmalloc(17);
memcpy(got, key->id, 17);
got[16] = '\0';
fatal("Secretkey sanity check: invalid key id (expected 16 bytes, got: %s)!\n", got);
free(got);
return 1;
}
struct tm *c;
time_t t = (time_t)key->ctime;
c = localtime(&t);
if(c->tm_year <= 0 || c->tm_year > 1100) {
// well, I'm perhaps overacting here :)
fatal("Secretkey sanity check: invalid creation timestamp (got year %04d)!\n", c->tm_year + 1900);
return 1;
}
pcp_key_t *maybe = pcphash_keyexists(key->id);
if(maybe != NULL) {
fatal("Secretkey sanity check: there already exists a key with the id 0x%s\n", key->id);
return 1;
}
return 0;
}