jettero / crypt--pbc

Crypt::PBC is an OO interface for the Stanford PBC

This URL has Read+Write access

crypt--pbc / PBC.xs
100644 95 lines (67 sloc) 1.602 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <pbc.h>
 
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
 
#include "ppport.h"
 
MODULE = Crypt::PBC PACKAGE = Crypt::PBC
 
PROTOTYPES: ENABLE
 
INCLUDE: pairing.xs
INCLUDE: einit.xs
INCLUDE: earith.xs
INCLUDE: ecomp.xs
 
void
element_fprintf(stream,format,element)
    FILE * stream
    char * format
    element_t * element
 
    CODE:
    element_fprintf(stream, format, *element);
 
SV *
export_element(element)
    element_t * element
 
    PREINIT:
    char *buf;
    int len;
    
    CODE:
    len = element_length_in_bytes(*element);
    buf = malloc( len + 2 );
 
    // My bug posted to the pbc-dev newsgroup, where I was getting different
    // results for different elements that test equal? Yeah, the following
    // line was not present when I got that result. I'm awesome. 11/15/06
    element_to_bytes(buf, *element);
 
    RETVAL = newSVpvn(buf, len);
 
    free(buf);
 
    OUTPUT:
    RETVAL
 
mpz_t *
element_to_mpz(element)
    element_t * element
 
    PREINIT:
    mpz_t * ret = malloc (sizeof(mpz_t));
 
    CODE:
    mpz_init(*ret);
    element_to_mpz(*ret, *element);
    RETVAL = ret;
 
    OUTPUT:
    RETVAL
 
int
element_length_in_bytes(element)
    element_t * element
 
    CODE:
    RETVAL = element_length_in_bytes(*element);
 
    OUTPUT:
    RETVAL
 
SV *
element_order(element)
    element_t * element
 
    PREINIT:
    int i;
    char *c;
 
    CODE:
    i = mpz_sizeinbase(element[0]->field->order, 10);
    c = malloc(i + 2);
 
    mpz_get_str(c, 10, element[0]->field->order);
 
    RETVAL = newSVpv(c, strlen(c));
    free(c);
 
    OUTPUT:
    RETVAL