예제 #1
0
파일: sync_api.c 프로젝트: IthacaDream/ccnx
int
ccns_slice_name(struct ccn_charbuf *nm, struct ccns_slice *s)
{
    struct ccn_charbuf *c;
    struct ccn_digest *digest = NULL;
    struct ccn_charbuf *hash = NULL;
    int res = 0;

    c = ccn_charbuf_create();
    if (c == NULL)
        return (-1);
    res = append_slice(c, s);
    if (res < 0)
        goto Cleanup;

    digest = ccn_digest_create(CCN_DIGEST_SHA256);
    hash = ccn_charbuf_create_n(ccn_digest_size(digest));
    if (hash == NULL)
        goto Cleanup;
    ccn_digest_init(digest);
    res |= ccn_digest_update(digest, c->buf, c->length);
    res |= ccn_digest_final(digest, hash->buf, hash->limit);
    if (res < 0)
        goto Cleanup;
    hash->length = hash->limit;
    if (ccn_name_from_uri(nm, "ccnx:/%C1.M.S.localhost/%C1.S.cs") < 0)
        res = -1;
    res |= ccn_name_append(nm, hash->buf, hash->length);

Cleanup:
    ccn_charbuf_destroy(&c);
    ccn_digest_destroy(&digest);
    ccn_charbuf_destroy(&hash);
    return (res);
}
예제 #2
0
파일: key_utils.c 프로젝트: Emat12/PyCCN
static int
create_key_digest(const unsigned char *dkey, size_t dkey_size,
		unsigned char **o_key_digest, size_t *o_key_digest_size)
{
	struct ccn_digest *digest;
	unsigned char *key_digest = NULL;
	size_t key_digest_size;
	int r;

	assert(o_key_digest);
	assert(o_key_digest_size);

	digest = ccn_digest_create(CCN_DIGEST_SHA256);
	JUMP_IF_NULL(digest, error);

	ccn_digest_init(digest);
	key_digest_size = ccn_digest_size(digest);

	key_digest = malloc(key_digest_size);
	JUMP_IF_NULL(key_digest, error);

	r = ccn_digest_update(digest, dkey, dkey_size);
	JUMP_IF_NEG(r, error);

	r = ccn_digest_final(digest, key_digest, key_digest_size);
	JUMP_IF_NEG(r, error);

	ccn_digest_destroy(&digest);

	*o_key_digest = key_digest;
	*o_key_digest_size = key_digest_size;

	return 0;

error:
	PyErr_SetString(g_PyExc_CCNKeyError, "unable to generate key digest");
	if (key_digest)
		free(key_digest);
	ccn_digest_destroy(&digest);
	return -1;
}
예제 #3
0
파일: ccn_match.c 프로젝트: futtre/ccnx
/**
 * Compute the digest of the entire ContentObject if necessary,
 * caching the result in pc->digest, pc->digest_bytes.
 */
void
ccn_digest_ContentObject(const unsigned char *content_object,
                         struct ccn_parsed_ContentObject *pc)
{
    int res;
    struct ccn_digest *d = NULL;

    if (pc->magic < 20080000) abort();
    if (pc->digest_bytes == sizeof(pc->digest))
        return;
    if (pc->digest_bytes != 0) abort();
    d = ccn_digest_create(CCN_DIGEST_SHA256);
    ccn_digest_init(d);
    res = ccn_digest_update(d, content_object, pc->offset[CCN_PCO_E]);
    if (res < 0) abort();
    res = ccn_digest_final(d, pc->digest, sizeof(pc->digest));
    if (res < 0) abort();
    if (pc->digest_bytes != 0) abort();
    pc->digest_bytes = sizeof(pc->digest);
    ccn_digest_destroy(&d);
}