1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
|
|
4 | |
|
|
5 | #include "perlmulticore.h" |
4 | |
6 | |
5 | /* work around unportable mess in fixedint.h */ |
7 | /* work around unportable mess in fixedint.h */ |
6 | /* taken from libecb */ |
8 | /* taken from libecb */ |
7 | #ifdef _WIN32 |
9 | #ifdef _WIN32 |
8 | typedef signed char int8_t; |
10 | typedef signed char int8_t; |
… | |
… | |
79 | { |
81 | { |
80 | secret_p = SvPVbyte (secret, secret_l); |
82 | secret_p = SvPVbyte (secret, secret_l); |
81 | |
83 | |
82 | if (secret_l != 32) |
84 | if (secret_l != 32) |
83 | croak ("Crypt::Ed25519::eddsa_public_key: secret has wrong length (!= 32)"); |
85 | croak ("Crypt::Ed25519::eddsa_public_key: secret has wrong length (!= 32)"); |
|
|
86 | |
|
|
87 | perlinterp_release (); |
|
|
88 | ed25519_create_keypair (public_key, private_key, secret_p); |
|
|
89 | perlinterp_acquire (); |
84 | } |
90 | } |
85 | else |
91 | else |
86 | { |
92 | { |
|
|
93 | perlinterp_release (); |
|
|
94 | |
87 | if (ed25519_create_seed (seed)) |
95 | if (ed25519_create_seed (seed)) |
|
|
96 | { |
|
|
97 | perlinterp_acquire (); |
88 | croak ("Crypt::Ed25519::generate_keypair: ed25519_create_seed failed"); |
98 | croak ("Crypt::Ed25519::generate_keypair: ed25519_create_seed failed"); |
|
|
99 | } |
89 | |
100 | |
90 | secret_p = seed; |
101 | secret_p = seed; |
|
|
102 | |
|
|
103 | ed25519_create_keypair (public_key, private_key, secret_p); |
|
|
104 | |
|
|
105 | perlinterp_acquire (); |
91 | } |
106 | } |
92 | |
|
|
93 | ed25519_create_keypair (public_key, private_key, secret_p); |
|
|
94 | |
107 | |
95 | EXTEND (SP, 2); |
108 | EXTEND (SP, 2); |
96 | PUSHs (sv_2mortal (newSVpvn (public_key, sizeof public_key))); |
109 | PUSHs (sv_2mortal (newSVpvn (public_key, sizeof public_key))); |
97 | |
110 | |
98 | if (!ix) |
111 | if (!ix) |
… | |
… | |
132 | { |
145 | { |
133 | if (private_key_l != 64) |
146 | if (private_key_l != 64) |
134 | croak ("Crypt::Ed25519::sign: private key has wrong length (!= 64)"); |
147 | croak ("Crypt::Ed25519::sign: private key has wrong length (!= 64)"); |
135 | } |
148 | } |
136 | |
149 | |
|
|
150 | perlinterp_release (); |
137 | ed25519_sign (signature, message_p, message_l, public_key_p, private_key_p); |
151 | ed25519_sign (signature, message_p, message_l, public_key_p, private_key_p); |
|
|
152 | perlinterp_acquire (); |
138 | |
153 | |
139 | RETVAL = newSVpvn (signature, sizeof signature); |
154 | RETVAL = newSVpvn (signature, sizeof signature); |
140 | } |
155 | } |
141 | OUTPUT: |
156 | OUTPUT: |
142 | RETVAL |
157 | RETVAL |
… | |
… | |
154 | STRLEN public_key_l; char *public_key_p = SvPVbyte (public_key, public_key_l); |
169 | STRLEN public_key_l; char *public_key_p = SvPVbyte (public_key, public_key_l); |
155 | |
170 | |
156 | if (public_key_l != 32) |
171 | if (public_key_l != 32) |
157 | croak ("Crypt::Ed25519::verify: public key has wrong length (!= 32)"); |
172 | croak ("Crypt::Ed25519::verify: public key has wrong length (!= 32)"); |
158 | |
173 | |
|
|
174 | perlinterp_release (); |
159 | RETVAL = ed25519_verify (signature_p, message_p, message_l, public_key_p); |
175 | RETVAL = ed25519_verify (signature_p, message_p, message_l, public_key_p); |
|
|
176 | perlinterp_acquire (); |
160 | |
177 | |
161 | if (!RETVAL && ix) |
178 | if (!RETVAL && ix) |
162 | croak ("Crypt::Ed25519::verify_croak: signature verification failed"); |
179 | croak ("Crypt::Ed25519::verify_croak: signature verification failed"); |
163 | } |
180 | } |
164 | OUTPUT: |
181 | OUTPUT: |