]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ec/ec.c
5 * Elliptic Curve Arithmetic Functions
7 * Copyright (C) Lenka Fibikova 2000
25 ret
=(EC
*)malloc(sizeof(EC
));
26 if (ret
== NULL
) return NULL
;
32 if (ret
->A
== NULL
|| ret
->B
== NULL
|| ret
->p
== NULL
)
34 if (ret
->A
!= NULL
) BN_free(ret
->A
);
35 if (ret
->B
!= NULL
) BN_free(ret
->B
);
36 if (ret
->p
!= NULL
) BN_free(ret
->p
);
44 void EC_clear_free(EC
*E
)
46 if (E
== NULL
) return;
48 if (E
->A
!= NULL
) BN_clear_free(E
->A
);
49 if (E
->B
!= NULL
) BN_clear_free(E
->B
);
50 if (E
->p
!= NULL
) BN_clear_free(E
->p
);
57 int EC_to_montgomery(EC
*E
, BN_MONTGOMERY
*mont
, BN_CTX
*ctx
)
60 assert(E
->A
!= NULL
&& E
->B
!= NULL
&& E
->p
!= NULL
);
63 assert(mont
->p
!= NULL
);
67 if (E
->is_in_mont
) return 1;
69 if (!BN_lshift(E
->A
, E
->A
, mont
->R_num_bits
)) return 0;
70 if (!BN_mod(E
->A
, E
->A
, mont
->p
, ctx
)) return 0;
72 if (!BN_lshift(E
->B
, E
->B
, mont
->R_num_bits
)) return 0;
73 if (!BN_mod(E
->B
, E
->B
, mont
->p
, ctx
)) return 0;
81 int EC_from_montgomery(EC
*E
, BN_MONTGOMERY
*mont
, BN_CTX
*ctx
)
84 assert(E
->A
!= NULL
&& E
->B
!= NULL
&& E
->p
!= NULL
);
87 assert(mont
->p
!= NULL
);
91 if (!E
->is_in_mont
) return 1;
93 if (!BN_mont_red(E
->A
, mont
)) return 0;
94 if (!BN_mont_red(E
->B
, mont
)) return 0;
99 #endif /* MONTGOMERY */