/** reference a revision by name */ int shfs_rev_ref(shfs_ino_t *file, char *group, char *name, shfs_ino_t *rev) { shfs_ino_t *branch; shfs_ino_t *ref; shkey_t *ref_key; char buf[SHFS_PATH_MAX]; int err; if (!rev) { return (SHERR_INVAL); } if (shfs_type(rev) != SHINODE_REVISION) return (SHERR_INVAL); ref_key = shkey_hexgen(shfs_filename(rev)); if (!ref_key) return (SHERR_IO); if (shkey_cmp(ref_key, ashkey_blank())) { /* not a revision (filename has no hex key) */ shkey_free(&ref_key); return (SHERR_INVAL); } memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf)-1, "%s/%s", group, name); err = shfs_obj_set(file, buf, ref_key); shkey_free(&ref_key); if (err) return (err); return (0); }
int txop_contract_confirm(shpeer_t *peer, tx_contract_t *contract) { shtime_t now; shkey_t *key; int sig_ok; if (0 != strcmp(contract->con_cur, COIN_USDE) && 0 != strcmp(contract->con_cur, COIN_GMC) && 0 != strcmp(contract->con_cur, COIN_SYS)) return (SHERR_INVAL); now = shtime(); if (shtime_before(shtime(), contract->con_birth) || shtime_before(shtime(), contract->con_stamp) || shtime_after(contract->con_birth, contract->con_stamp)) return (SHERR_TIME); key = shkey_hexgen(contract->con_key + 8); if (!key) return (SHERR_NOKEY); sig_ok = shkey_cmp(key, &contract->con_sig); shkey_free(&key); if (!sig_ok) return (SHERR_KEYREJECTED); return (0); }
int txop_contract_init(shpeer_t *cli_peer, tx_contract_t *contract) { shkey_t *key; contract->con_birth = shtime(); key = shkey_hexgen(contract->con_key + 8); if (!key) return (SHERR_NOKEY); memcpy(&contract->con_sig, key, sizeof(contract->con_sig)); shkey_free(&key); contract->con_stamp = shtime(); return (0); }
/** * Generate a public key. */ shkey_t *shecdsa_key_priv(char *hex_seed) { #ifdef HAVE_LIBGMP ecdsa_parameters curve; mpz_t d; shkey_t *ret_key; shkey_t *ukey; #if 0 /* setup parameters */ curve = ecdsa_parameters_init(); ecdsa_parameters_load_curve(curve, secp160r1); /* public key */ ecdsa_point Q = ecdsa_point_init(); ecdsa_point Q_check = ecdsa_point_init(); #endif if (hex_seed) { ukey = shkey_hexgen(hex_seed); } else { ukey = shkey_uniq(); /* generate random */ } if (!ukey) { fprintf(stderr, "DEBUG: shecdsa_key_priv: !ukey\n"); return (NULL); } /* truncate to "21 bytes" */ ukey->code[5] = (ukey->code[5] & 0xff); ukey->code[6] = 0; ukey->code[7] = 0; ukey->alg = SHKEY_ALG_ECDSA; ret_key = shecdsa_key((char *)shkey_hex(ukey)); shkey_free(&ukey); return (ret_key); #else return (NULL); #endif }