示例#1
0
文件: point.c 项目: 01org/opa-ff
/* append object to the ExpectedLink list
 * if this is the 1st insert to a "None" Point, it will initialize the
 * list and set the point enode type.
 * Failures imply a caller bug or a failure to allocate memory
 * On failure, the point is destroyed by this routine
 */
FSTATUS PointElinkListAppend(Point *point, PointElinkType type, void *object)
{
	FSTATUS status;
	DLIST *pList;

	if (point->ElinkType == POINT_ELINK_TYPE_NONE) {
		status = PointInitElinkList(point, type);
		if (FSUCCESS != status) {
			PointDestroy(point);
			return status;
		}
	} else if (type != point->ElinkType) {
		ASSERT(0);
		PointDestroy(point);
		return FINVALID_OPERATION;
	}
	switch (type) {
	case POINT_ELINK_TYPE_LINK_LIST:
		pList = &point->u4.elinkList;
		break;
	default:
		ASSERT(0);
		PointDestroy(point);
		return FINVALID_OPERATION;
	}
	if (! ListInsertTail(pList, object)) {
		fprintf(stderr, "%s: unable to allocate memory\n", g_Top_cmdname);
		PointDestroy(point);
		return FINSUFFICIENT_MEMORY;
	}
	return FSUCCESS;
}
示例#2
0
文件: main.c 项目: Ceylo/CryptoA5
static void addPteta(PointRef p, PointRef q, CurveRef curve) {
    PointRef r = PointCreateAdd(p, q, curve);
    
	assert(mpz_cmp_si(r->x, 3) == 0);
	assert(mpz_cmp_si(r->y, 1) == 0);
    
    PointDestroy(r);
}
示例#3
0
文件: main.c 项目: Ceylo/CryptoA5
static void addResultTeta(PointRef p, PointRef q, CurveRef curve) {
    PointRef r = PointCreateAdd(p, q, curve);
    
	assert(mpz_cmp_si(r->x, 0) == 0);
	assert(mpz_cmp_si(r->y, 0) == 0);
    assert(r->infinite == true);
    
    PointDestroy(r);
}
示例#4
0
文件: point.c 项目: 01org/opa-ff
/* append object to the list
 * if this is the 1st insert to a "None" Point, it will initialize the
 * list and set the point type.
 * On failure, the point is destroyed by this routine
 */
FSTATUS PointListAppend(Point *point, PointType type, void *object)
{
	FSTATUS status;
	DLIST *pList;

	if (point->Type == POINT_TYPE_NONE) {
		status = PointInitList(point, type);
		if (FSUCCESS != status) {
			PointDestroy(point);
			return status;
		}
	} else if (type != point->Type) {
		ASSERT(0);
		PointDestroy(point);
		return FINVALID_OPERATION;
	}
	switch (type) {
	case POINT_TYPE_PORT_LIST:
		pList = &point->u.portList;
		break;
	case POINT_TYPE_NODE_LIST:
		pList = &point->u.nodeList;
		break;
#if !defined(VXWORKS) || defined(BUILD_DMC)
	case POINT_TYPE_IOC_LIST:
		pList = &point->u.iocList;
		break;
#endif
	default:
		ASSERT(0);
		PointDestroy(point);
		return FINVALID_OPERATION;
	}
	if (! ListInsertTail(pList, object)) {
		fprintf(stderr, "%s: unable to allocate memory\n", g_Top_cmdname);
		PointDestroy(point);
		return FINSUFFICIENT_MEMORY;
	}
	return FSUCCESS;
}
示例#5
0
文件: main.c 项目: Ceylo/CryptoA5
int main(int argc, const char * argv[])
{
    mpz_t a[7], mod, n;
    mpz_inits(a[0], a[1], a[2], a[3], a[4], a[5], a[6], n, NULL);
    mpz_init_set_si(mod, 5);
    mpz_set_si(a[4], 1);
    mpz_set_si(n, 5);
    
    PointRef g = PointCreateFromInt(0,1);
    PointRef p = PointCreateFromInt(2,4);
    PointRef q = PointCreateFromInt(3,1);
    PointRef pTeta = PointCreateTeta();
    PointRef qTeta = PointCreateTeta();
    PointRef p2 = PointCreateFromInt(3,2);
    PointRef p2Inv = PointCreateFromInt(3,3);

    
    CurveRef curve = CurveCreate(mod, n, a, g);
    
    assert(curve != NULL);
	assert(curve->a[4] != NULL);
	assert(curve->a[6] != NULL);
	assert(curve->g != NULL);
	assert(curve->mod != NULL);
    
    addPoints(p, q, curve);
    
    addDoublePoint(p2, p2, curve);
    
    addPteta(pTeta, q, curve);
    
    addQteta(p, qTeta, curve);
    
    addResultTeta(p2, p2Inv, curve);
    
    mpz_clears(mod, a[0], a[1], a[2], a[3], a[4], a[5], a[6], NULL);
    PointDestroy(g);
    PointDestroy(p);
    PointDestroy(q);
    PointDestroy(pTeta);
    PointDestroy(qTeta);
    PointDestroy(p2);
    PointDestroy(p2Inv);
    
    CurveDestroy(curve);

    return 0;
}