Package list libcryptx-perl / 3522cca
drop sign_hash/verify_hash; just keeep sign_message/verify_message Karel Miko 1 year, 8 months ago
2 changed file(s) with 16 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
205205 RETVAL
206206
207207 SV *
208 sign_hash(Crypt::PK::Ed25519 self, SV * data, const char * hash_name = "SHA1")
209 ALIAS:
210 sign_message = 1
211 CODE:
212 {
213 int rv, id;
214 unsigned char buffer[1024], tmp[MAXBLOCKSIZE], *data_ptr = NULL;
215 unsigned long tmp_len = MAXBLOCKSIZE, buffer_len = 1024;
208 sign_message(Crypt::PK::Ed25519 self, SV * data)
209 CODE:
210 {
211 int rv;
212 unsigned char buffer[64], *data_ptr = NULL;
213 unsigned long buffer_len = 64;
216214 STRLEN data_len = 0;
217215
218216 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
219 if (ix == 1) {
220 id = _find_hash(hash_name);
221 if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name);
222 rv = hash_memory(id, data_ptr, (unsigned long)data_len, tmp, &tmp_len);
223 if (rv != CRYPT_OK) croak("FATAL: hash_memory failed: %s", error_to_string(rv));
224 data_ptr = tmp;
225 data_len = tmp_len;
226 }
227217 rv = ed25519_sign(data_ptr, (unsigned long)data_len, buffer, &buffer_len, &self->key);
228218 if (rv != CRYPT_OK) croak("FATAL: ed25519_sign failed: %s", error_to_string(rv));
229219 RETVAL = newSVpvn((char*)buffer, buffer_len);
232222 RETVAL
233223
234224 int
235 verify_hash(Crypt::PK::Ed25519 self, SV * sig, SV * data, const char * hash_name = "SHA1")
236 ALIAS:
237 verify_message = 1
238 CODE:
239 {
240 int rv, stat, id;
241 unsigned char tmp[MAXBLOCKSIZE], *data_ptr = NULL, *sig_ptr = NULL;
242 unsigned long tmp_len = MAXBLOCKSIZE;
225 verify_message(Crypt::PK::Ed25519 self, SV * sig, SV * data)
226 CODE:
227 {
228 int rv, stat;
229 unsigned char *data_ptr = NULL, *sig_ptr = NULL;
243230 STRLEN data_len = 0, sig_len = 0;
244231
245232 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
246233 sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
247 if (ix == 1) {
248 id = _find_hash(hash_name);
249 if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name);
250 rv = hash_memory(id, data_ptr, (unsigned long)data_len, tmp, &tmp_len);
251 if (rv != CRYPT_OK) croak("FATAL: hash_memory failed: %s", error_to_string(rv));
252 data_ptr = tmp;
253 data_len = tmp_len;
254 }
255 RETVAL = 1;
234 RETVAL = 0;
256235 stat = 0;
257236 rv = ed25519_verify(data_ptr, (unsigned long)data_len, sig_ptr, (unsigned long)sig_len, &stat, &self->key);
258 if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
237 if (rv == CRYPT_OK && stat == 1) RETVAL = 1;
259238 }
260239 OUTPUT:
261240 RETVAL
326326
327327 Export raw public/private key
328328
329 my $private_pem = $pk->export_key_raw('private');
330 #or
331 my $public_pem = $pk->export_key_raw('public');
329 my $private_bytes = $pk->export_key_raw('private');
330 #or
331 my $public_bytes = $pk->export_key_raw('public');
332332
333333 =head2 sign_message
334334
335335 my $signature = $priv->sign_message($message);
336 #or
337 my $signature = $priv->sign_message($message, $hash_name);
338
339 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
340336
341337 =head2 verify_message
342338
343339 my $valid = $pub->verify_message($signature, $message)
344 #or
345 my $valid = $pub->verify_message($signature, $message, $hash_name);
346
347 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
348340
349341 =head2 is_private
350342