Commit f4555f5c650f1005c018d18d178ec936dcae9742

MAINTENENCE: added documentation to a few methods
pypbc.c
(36 / 9)
  
99
1010This file contains the types and functions needed to use PBC from Python3.
1111*******************************************************************************/
12
12PyDoc_STRVAR(pynum_to_mpz__doc__,
13 "Converts a Python long type to a GMP MPZ type");
1314void pynum_to_mpz(PyObject *n, mpz_t new_n) {
1415 // coerce it into a string
1516 PyObject *n_unicode = PyNumber_ToBase(n, 10);
2121 mpz_init_set_str(new_n, n_char, 10);
2222}
2323
24PyDoc_STRVAR(mpz_to_pynum__doc__,
25 "Converts a GMP MPZ type to a Python long");
2426PyObject *mpz_to_pynum(mpz_t n) {
2527 // get the mpz as a string
2628 char *s = mpz_get_str(NULL, 10, n);
3737 return l;
3838}
3939
40PyDoc_STRVAR(get_random_prime__doc__,
41 "Returns a random prime in the given bitlength.");
4042PyObject *get_random_prime(PyObject *self, PyObject *args) {
4143 // gets the number of bits from the args
4244 int num_bits;
6666 return rand_prime;
6767}
6868
69PyDoc_STRVAR(get_random__doc__,
70 "Returns a random integer less than the given value.");
6971PyObject *get_random(PyObject *self, PyObject *args) {
7072 // gets the number of bits from the args
7173 PyObject *max;
101101/*******************************************************************************
102102* Params *
103103*******************************************************************************/
104PyDoc_STRVAR(Parameters__doc__,
105"A representation of the parameters of an elliptic curve.\n\n\
106There are three basic ways to instantiate a Parameters object:\n\
107Parameters(param_string=s) -> a set of parameters built according to s.\n\
108Parameters(n=x, short=True/False) -> a type A1 or F curve.\n\
109Parameters(qbits=q, rbits=r, short=True/False) -> type A or E curve.\n\
110\n\
111These objects are essentially only used for creating Pairings.");
104112
105113// allocate the object
106114PyObject *Parameters_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
249249 0, /*tp_setattro*/
250250 0, /*tp_as_buffer*/
251251 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
252 "Parameters objects", /* tp_doc */
252 Parameters__doc__, /* tp_doc */
253253 0, /* tp_traverse */
254254 0, /* tp_clear */
255255 0, /* tp_richcompare */
274274* Pairings *
275275*******************************************************************************/
276276
277// personal note: to generate the a1 pairings you need, use
278// pbc_param_init_a1_gen(pbc_param_t param, mpz_t n) with
279// n = pqr, p, q, r large primes!
280
277PyDoc_STRVAR(Pairing__doc__,
278"Pairing(parameters) -> Pairing object\n\n\
279Represents a bilinear pairing, frequently referred to as e-hat.\n");
281280// allocate the object
282281PyObject *Pairing_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
283282 // create the new Pairing object
408408 0, /*tp_setattro*/
409409 0, /*tp_as_buffer*/
410410 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
411 "Pairing objects", /* tp_doc */
411 Pairing__doc__, /* tp_doc */
412412 0, /* tp_traverse */
413413 0, /* tp_clear */
414414 0, /* tp_richcompare */
432432* Elements *
433433*******************************************************************************/
434434
435PyDoc_STRVAR(Element__doc__,
436"Represents an element of a bilinear group.\n\n\
437Basic usage:\n\
438\n\
439Element(pairing, G1||G2||GT||Zr, value=v) -> Element\n\
440Element.one(pairing, G1||G2||GT||Zr) -> identity element for the given group.\n\
441Element.zero(pairing, G1||G2||GT||Zr) -> identity element for the given group.\n\
442Element.random(pairing, G1||G2||GT||Zr) -> random element of the given group.\n\
443Element.from_hash(pairing, G1||G2||GT||Zr -> element whose value is determined by the given hash value.\n\
444\n\
445Most of the basic arithmetic operations apply. Please note that many of them\n\
446do not make sense between groups, and that not all of these are checked for.");
447
435448Element *Element_create(void) {
436449 // build ourselves
437450 Element *self = (Element*)(&ElementType)->tp_alloc(&ElementType, 0);
534534}
535535
536536PyObject *Element_from_hash(PyObject *cls, PyObject *args) {
537 // required arguments are the pairing, the group, and the value to be hashed
537 // required arguments are the pairing, the group, and the hashed value
538538 PyObject *pypairing;
539539 enum Group group;
540540 char *hash;
10921092 0, /*tp_setattro*/
10931093 0, /*tp_as_buffer*/
10941094 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1095 "Element objects", /* tp_doc */
1095 Element__doc__, /* tp_doc */
10961096 0, /* tp_traverse */
10971097 0, /* tp_clear */
10981098 Element_cmp, /* tp_richcompare */