예제 #1
0
파일: client.c 프로젝트: ep69/tang
static TANG_MSG *
rec(int sock, EC_KEY *key, const char *file, int line)
{
    TANG_MSG_REC_REQ *req = NULL;
    const EC_GROUP *grp = NULL;
    TANG_MSG *rep = NULL;

    test(grp = EC_KEY_get0_group(key));
    test(req = TANG_MSG_REC_REQ_new());
    test(conv_eckey2gkey(key, TANG_KEY_USE_REC, req->key, NULL) == 0);
    test(conv_point2os(grp, EC_GROUP_get0_generator(grp), req->x, NULL) == 0);
    test(rep = request(sock, &(TANG_MSG) {
        .type = TANG_MSG_TYPE_REC_REQ,
        .val.rec.req = req
    }, file, line));
예제 #2
0
파일: conv.c 프로젝트: tiran/tang
int
conv_eckey2gkey(EC_KEY *key, TANG_KEY_USE use, TANG_KEY *gkey, BN_CTX *ctx)
{
    const EC_GROUP *grp = EC_KEY_get0_group(key);
    int r;

    if (!grp)
        return EINVAL;

    ASN1_OBJECT_free(gkey->grp);
    gkey->grp = OBJ_nid2obj(EC_GROUP_get_curve_name(grp));
    if (!gkey->grp)
        return ENOMEM;

    r = conv_point2os(grp, EC_KEY_get0_public_key(key), gkey->key, ctx);
    if (r != 0)
        return ENOMEM;

    if (ASN1_ENUMERATED_set(gkey->use, use) <= 0)
        return ENOMEM;

    return 0;
}