Codebase list libcryptx-perl / ce8c5da
doc fixes Karel Miko 10 years ago
5 changed file(s) with 65 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
208208 my $ct = dh_encrypt(\$buffer_containing_pub_key, $message);
209209 #or
210210 my $ct = dh_encrypt($pub_key_filename, $message, $hash_name);
211
212 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
213
214 Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DH key is computed, and
215 the hash of the shared key XOR'ed against the plaintext forms the ciphertext.
211216
212217 =head2 dh_decrypt
213218
292297
293298 =head2 import_key
294299
300 Loads private or public key (exported by L</export_key>).
301
295302 $pk->import_key($filename);
296303 #or
297304 $pk->import_key(\$buffer_containing_key);
309316 #or
310317 my $ct = $pk->encrypt($message, $hash_name);
311318
312 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
319 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
313320
314321 =head2 decrypt
315322
323330 #or
324331 my $signature = $priv->sign_message($message, $hash_name);
325332
326 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
333 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
327334
328335 =head2 verify_message
329336
332339 #or
333340 my $valid = $pub->verify_message($signature, $message, $hash_name);
334341
335 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
342 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
336343
337344 =head2 sign_hash
338345
365372
366373 =head2 size
367374
368 my $size = $pk->is_private;
375 my $size = $pk->size;
369376 # returns key size in bytes or undef if no key loaded
370377
371378 =head2 key2hash
374381
375382 # returns hash like this (or undef if no key loaded):
376383 {
377 type => 0,
378 size => 256,
379 name => "DH-2048",
380 x => "FBC1062F73B9A17BB8473A2F5A074911FA7F20D28FB...",
381 y => "AB9AAA40774D3CD476B52F82E7EE2D8A8D40CD88BF4...",
382 }
384 type => 0, # integer: 1 .. private, 0 .. public
385 size => 256, # integer: key size in bytes
386 name => "DH-2048", # internal libtomcrypt name
387 x => "FBC1062F73B9A17BB8473A2F5A074911FA7F20D28FB...", #private key
388 y => "AB9AAA40774D3CD476B52F82E7EE2D8A8D40CD88BF4...", #public key
389 }
213213
214214 =head2 dsa_encrypt
215215
216 DSA based encryption. See method L</encrypt> below.
217
218 my $pt = dsa_decrypt($priv_key_filename, $ciphertext);
219 #or
220 my $pt = dsa_decrypt(\$buffer_containing_priv_key, $ciphertext);
221
222 Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared key is computed, and
216 DSA based encryption as implemented by libtomcrypt. See method L</encrypt> below.
217
218 my $ct = dsa_encrypt($pub_key_filename, $message);
219 #or
220 my $ct = dsa_encrypt(\$buffer_containing_pub_key, $message);
221 #or
222 my $ct = dsa_encrypt($pub_key_filename, $message, $hash_name);
223
224 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
225
226 Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DSA key is computed, and
223227 the hash of the shared key XOR'ed against the plaintext forms the ciphertext.
224228
225229 =head2 dsa_decrypt
226230
227 DSA based decryption. See method L</decrypt> below.
231 DSA based decryption as implemented by libtomcrypt. See method L</decrypt> below.
228232
229233 my $pt = dsa_decrypt($priv_key_filename, $ciphertext);
230234 #or
300304
301305 =head2 import_key
302306
307 Loads private or public key in DER or PEM format (password protected keys are not supported).
308
303309 $pk->import_key($filename);
304310 #or
305311 $pk->import_key(\$buffer_containing_key);
320326
321327 my $pk = Crypt::PK::DSA->new($pub_key_filename);
322328 my $ct = $pk->encrypt($message);
329 #or
330 my $ct = $pk->encrypt($message, $hash_name);
331
332 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
323333
324334 =head2 decrypt
325335
333343 #or
334344 my $signature = $priv->sign_message($message, $hash_name);
335345
336 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
346 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
337347
338348 =head2 verify_message
339349
342352 #or
343353 my $valid = $pub->verify_message($signature, $message, $hash_name);
344354
345 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
355 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
346356
347357 =head2 sign_hash
348358
363373
364374 =head2 size
365375
366 my $size = $pk->is_private;
376 my $size = $pk->size;
367377 # returns key size in bytes or undef if no key loaded
368378
369379 =head2 key2hash
211211
212212 =head2 ecc_encrypt
213213
214 Elliptic Curve Diffie-Hellman (ECDH) encryption.
215
216 ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext. See method L</encrypt> below.
214 Elliptic Curve Diffie-Hellman (ECDH) encryption as implemented by libtomcrypt. See method L</encrypt> below.
217215
218216 my $ct = ecc_encrypt($pub_key_filename, $message);
219217 #or
220218 my $ct = ecc_encrypt(\$buffer_containing_pub_key, $message);
219 #or
220 my $ct = ecc_encrypt($pub_key_filename, $message, $hash_name);
221
222 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
223
224 ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext.
221225
222226 =head2 ecc_decrypt
223227
224 Elliptic Curve Diffie-Hellman (ECDH) decryption. See method L</decrypt> below.
228 Elliptic Curve Diffie-Hellman (ECDH) decryption as implemented by libtomcrypt. See method L</decrypt> below.
225229
226230 my $pt = ecc_decrypt($priv_key_filename, $ciphertext);
227231 #or
303307
304308 =head2 import_key
305309
310 Loads private or public key in DER format (exported by L</export_key_der>).
311
306312 $pk->import_key($filename);
307313 #or
308314 $pk->import_key(\$buffer_containing_key);
309315
310316 =head2 import_key_x963
311317
312 ANSI X9.63 Import (public key only) - can load data exported by C<export_key_x963>
318 ANSI X9.63 Import (public key only) - can load data exported by L</export_key_x963>.
313319
314320 $pk->import_key(\$buffer_containing_pub_key_ansi_x963);
315321
329335
330336 my $pk = Crypt::PK::ECC->new($pub_key_filename);
331337 my $ct = $pk->encrypt($message);
338 #or
339 my $ct = $pk->encrypt($message, $hash_name);
340
341 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
332342
333343 =head2 decrypt
334344
342352 #or
343353 my $signature = $priv->sign_message($message, $hash_name);
344354
345 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
355 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
346356
347357 =head2 verify_message
348358
351361 #or
352362 my $valid = $pub->verify_message($signature, $message, $hash_name);
353363
354 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by L<Crypt::Digest>
364 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
355365
356366 =head2 sign_hash
357367
384394
385395 =head2 size
386396
387 my $size = $pk->is_private;
397 my $size = $pk->size;
388398 # returns key size in bytes or undef if no key loaded
389399
390400 =head2 key2hash
393403
394404 # returns hash like this (or undef if no key loaded):
395405 {
396 type => 1,
397 size => 32,
406 type => 1, # integer: 1 .. private, 0 .. public
407 size => 32, # integer: key (curve) size in bytes
408 #curve parameters
398409 curve_name => "ECC-256",
399410 curve_size => 32,
400411 curve_B => "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",
402413 curve_Gy => "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5",
403414 curve_order => "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551",
404415 curve_prime => "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
416 #private key
405417 k => "A7F43ACD4A05D69AE4597E6E723EB5F1E9B9B7EAA51B6DE83CF36F9687B57DEE",
418 #public key point coordinates
406419 pub_x => "AB53ED5D16CE550BAAF16BA4F161332AAD56D63790629C27871ED515D4FC229C",
407420 pub_y => "78FC34C6A320E22672A96EBB6DA48387A40541A3D7E5CFAE0D58A513E38C8888",
408421 pub_z => "1",
326326
327327 =head2 import_key
328328
329 Loads private or public key in DER or PEM format (password protected keys are not supported).
330
329331 $pk->import_key($priv_or_pub_key_filename);
330332 #or
331333 $pk->import_key(\$buffer_containing_priv_or_pub_key);
429431
430432 =head2 size
431433
432 my $size = $pk->is_private;
434 my $size = $pk->size;
433435 # returns key size in bytes or undef if no key loaded
434436
435437 =head2 key2hash
22 use strict;
33 use warnings ;
44
5 our $VERSION = '0.014';
5 our $VERSION = '0.015';
66
77 require XSLoader;
88 XSLoader::load('CryptX', $VERSION);