]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/CurveParamDocs/curvegen.c
1 /**************************************************************
9 * % cc -O curvegen.c tools.c giants.c ellproj.c -lm -o curvegen
12 * 27 Sep 98 REC - Creation
15 * c. 1998 Perfectly Scientific, Inc.
16 * All Rights Reserved.
19 *************************************************************/
39 int disc12
[DCOUNT
] = {-3, -4, -7, -8, -11, -19, -43, -67, -163, -15, -20, -24, -35, -40, -51, -52, -88, -91, -115, -123, -148, -187, -232, -235, -267, -403, -427}; /* All discriminants of class number 1,2. */
41 /**************************************************************
45 **************************************************************/
47 #define CM_SHORTS 4096
49 main(int argc
, char **argv
) {
50 giant p
= newgiant(CM_SHORTS
);
51 giant u
= newgiant(CM_SHORTS
);
52 giant v
= newgiant(CM_SHORTS
);
54 giant plus_order
= newgiant(CM_SHORTS
);
55 giant minus_order
= newgiant(CM_SHORTS
);
56 giant a
= newgiant(CM_SHORTS
);
57 giant b
= newgiant(CM_SHORTS
);
60 init_tools(CM_SHORTS
); /* Basic algorithms. */
61 printf("Give base prime p:\n"); fflush(stdout
);
63 for(dc
=0; dc
< 6; dc
++) g
[dc
] = newgiant(CM_SHORTS
);
64 for(dc
= 0; dc
< DCOUNT
; dc
++) {
66 /* Next, seek representation 4N = u^2 + |d| v^2. */
67 if(cornacchia4(p
, d
, u
, v
) == 0) continue;
68 /* Here, (u,v) give the quadratic representation of 4p. */
69 printf("D: %d\n", d
); fflush(stdout
);
72 case -3: olen
= 3; /* Six orders: p + 1 +- g[0,1,2]. */
73 gtog(u
, g
[1]); gtog(v
, g
[2]);
74 addg(g
[2], g
[2]); addg(v
, g
[2]); /* g[2] := 3v. */
75 addg(g
[2], g
[1]); gshiftright(1, g
[1]); /* g[1] = (u + 3v)/2. */
76 subg(u
, g
[2]); gshiftright(1, g
[2]); absg(g
[2]); /* g[2] = |u-3v|/2. */
78 case -4: olen
= 2; /* Four orders: p + 1 +- g[0,1]. */
79 gtog(v
, g
[1]); addg(g
[1], g
[1]); /* g[1] = 2v. */
81 default: olen
= 1; /* Two orders: p + 1 +- g[0]. */
83 for(k
=0; k
< olen
; k
++) {
84 gtog(p
, plus_order
); iaddg(1, plus_order
);
85 gtog(p
, minus_order
); iaddg(1, minus_order
);
86 addg(g
[k
], plus_order
);
87 subg(g
[k
], minus_order
);
88 printf("curve orders: \n");
89 printf("(%d) ", prime_probable(plus_order
));
91 printf("(%d) ", prime_probable(minus_order
));