Package list libcryptx-perl / 496d9b3
New upstream version 0.054 Damyan Ivanov 3 years ago
523 changed file(s) with 18125 addition(s) and 5510 deletion(s). Raw diff Collapse all Expand all
00 Changes for CryptX
11
22 TODO:
3 - add support for PKCS#8 encrypted RSA+ECC private keys "-----BEGIN ENCRYPTED PRIVATE KEY-----"
4 - RSA|DSA|ECC: verify_key($level) (basic check + extented primality test)
5 - better primality testing: http://questhub.io/realm/perl/quest/519032ee1088c76505000035 (idea: mp_prime_lucas)
6 - DSA: generate_key($p, $q, $g), generate_key(\$dsa_params_der), generate_key($dsa_params_file)
73 - XS croaks should report the "real caller" (Crypt::Mac::*, Crypt::Mode::*, ...)
8 - maybe: add CCM interface for new-add-add-done mode
9 - maybe: add encode_b32/decode_b32
10
11 0.048 2017/05/31
4 - CCM interface new-add-add-done
5
6 0.054 2017-10-12
7 - fix Crypt::PK::DSA verify
8 - libtomcrypt updated to 1.18 (+ some extra patches)
9 - documentation fixes
10
11 0.053 2017-09-15
12 - fix Crypt::PK::DSA generate_key
13
14 0.051 2017-08-08
15 - INCOMPATIBLE CHANGE: Crypt::AuthEnc::OCB is now compliant with RFC 7253
16
17 0.050 2017-07-18
18 - fix cpantesters failures/warnings
19
20 0.049 2017-07-18
21 - libtomcrypt updated to 1.18-rc2 (+ some extra patches)
22 - REMOVED: Crypt::PK::DH encrypt decrypt sign_message verify_message sign_hash verify_hash
23 - NEW: Crypt::Misc - encode_b32*, decode_b32*, encode_b58*, decode_b58*
24 - Crypt::PK::RSA: import public key from X509 certificate
25 - Crypt::PK::DSA: improved generate_key()
26 - Crypt::PK::DH: improved generate_key()
27 - fix #36 aad_add is obsolete for all EncAuth algs (correct is adata_add)
28 - fix #37 GCM - Encryption of the empty string
29
30 0.048 2017-05-31
1231 - NEW: Crypt::Digest::SHA3_224
1332 - NEW: Crypt::Digest::SHA3_256
1433 - NEW: Crypt::Digest::SHA3_384
3352 - NEW: functions in Crypt::Misc - increment_octets_be, increment_octets_le
3453 - Crypt::PRNG now uses chacha20 prng by default
3554
36 0.047 2017/04/05
55 0.047 2017-04-05
3756 - fix #32 Compile "ar" step fails when Perl built with -flto (better version)
3857 - fix #33 build fails on freebsd 9.2 and 10.0 (ar: fatal: Numeric group ID too large)
3958
40 0.046 2017/04/04
59 0.046 2017-04-04
4160 - fix #32 Compile "ar" step fails when Perl built with -flto
4261
43 0.045 2017/03/31
62 0.045 2017-03-31
4463 - sync with libtomcrypt/develop
4564 - fix #30 fix on SPARC+SolarisStudio
4665 - fix #31 Fails tests without '.' in @INC
4766 - polish compiler warnings
4867
49 0.044 2016/11/28
68 0.044 2016-11-28
5069 - fix #27 Math::BigInt::LTM compatibility with older Math::BigInt
5170
52 0.043 2016/11/27
71 0.043 2016-11-27
5372 - fix #26 Math::BigInt::LTM compatibility with Math::BigInt 1.999801+
5473
55 0.042 2016/11/12
74 0.042 2016-11-12
5675 - RSA: sign/verify functions now support 'none' padding (INSECURE!)
5776 - RC2: min keylen 40bit, used to be 64bit (INSECURE!)
5877
59 0.041 2016/10/12
78 0.041 2016-10-12
6079 - ECC: ltc_ecc_is_point memory leak
6180 - DSA: properly handle FIPS 186-4 (4.6 + 4.7)
6281 - GCM: counter incrementation isn't stopped at 2^32 blocks, which breaks GCM
6382 - fix issue #24 Crypt::PK::ECC needs $VERSION (all *.pm have $VERSION)
6483
65 0.040 2016/09/12
84 0.040 2016-09-12
6685 - fix file permissions
6786 - fix compiler warnings
6887
69 0.039 2016/08/02
88 0.039 2016-08-02
7089 - fix build troubles for MacOS / PPC
7190
72 0.038 2016/07/06
91 0.038 2016-07-06
7392 - fix issue #20 DSA/RSA/ECC/DH key2hash - hexadecimal numbers are missing leading zero
7493 - Math::BigInt::LTM fixed mp_invmod(a,b,c) for b == 1
7594 - Math::BigInt::LTM fixed _log_int()
7796 - fix 'Please specify prototyping behavior for CryptX.xs'
7897 - libtomcrypt (renaming *tab.c > *tab.c.inc not needed anymore)
7998
80 0.037 2016/06/16
99 0.037 2016-06-16
81100 - fix issue #18 Minor issue with comment syntax
82101 - fix issue #19 t/checksum.t fails on AIX-5.3
83102
84 0.036 2016/06/07
103 0.036 2016-06-07
85104 - fix issue #17 ability to export ecc keys in short/oid form
86105
87 0.035 2016/06/03
106 0.035 2016-06-03
88107 - fix issue #14 Ensure Crypt::PK::ECC->key2hash()->{curve_name} is lowercase
89108 - fix issue #15 OpenSSL interoperability broken
90109
91 0.034 2016/05/11
110 0.034 2016-05-11
92111 - Prevent RSA import_key() from altering a JWK hash reference
93112
94 0.033 2016/05/09
113 0.033 2016-05-09
95114 - MSVC6 related fixes (needed for older ActivePerl@MSWin32)
96115
97 0.032 2016/05/04
116 0.032 2016-05-04
98117 - Crypt::PK::DH - accept base/prime values
99118 - new: DH methods export_key_raw, import_key_raw, params2hash
100119 - enhanced: DH method generate_key
101120 - new: Crypt::Checksum, Crypt::Checksum::CRC32, Crypt::Checksum::Adler32
102121
103 0.031 2016/05/01
122 0.031 2016-05-01
104123 - new: RSA+ECC method export_key_jwk_thumbprint()
105124 - new: Crypt::Misc functions random_v4uuid + is_v4uuid
106125 - fix: RSA+ECC export_key_jwk produces canonical JSON
108127 public keys exported be previous version can still be imported
109128 - fix: ECC import_key now accepts non-standard JWK curve names e.g. "secp112r1", "secp521r1"
110129
111 0.030 2016/04/13
130 0.030 2016-04-13
112131 - fix: 0.029 + 0.028 by mistake installed *.inc files to perl/(lib|site|vendor)
113132
114 0.029 2016/04/13
133 0.029 2016-04-13
115134 - NEW module: Math::BigInt::LTM
116135 - NEW module: Crypt::Misc
117136
118 0.028 2016/03/23
137 0.028 2016-03-23
119138 - IMPORTANT: switch from Module::Build to ExtUtils::MakeMaker
120139 - fix for broken DSA key (ssh format) loading
121140
122 0.027 2016/01/25
141 0.027 2016-01-25
123142 - sync with https://github.com/libtom/libtomcrypt (branch develop)
124143 - sync with https://github.com/libtom/libtommath (branch develop)
125144 - HP-UX related fixes
127146 - skip jwk.t if no JSON::* module available
128147 - does not require MIME::Base64 (we use base64 routines from libtomcrypt)
129148
130 0.026 2015/11/28
149 0.026 2015-11-28
131150 - switch to JSON::MaybeXS
132151 - Crypt::PRNG - rand/irand related cosmetics
133152 - consistently using UNIX newlines
134153
135 0.025 2015/07/07
154 0.025 2015-07-07
136155 - Crypt::PK::ECC+RSA export_key_jwk() allows to export a perl HASH with JWK structure
137156
138 0.024 2015/06/29
157 0.024 2015-06-29
139158 - new Crypt::PK::ECC methods
140159 verify_message_rfc7518()
141160 sign_message_rfc7518()
142161 curve2hash()
143162 - fix for Crypt::PK::RSA - bug in loading private key in JWK format
144163
145 0.023 2015/06/10
164 0.023 2015-06-10
146165 - support for older compilers (gcc3, vc6)
147166 - typo in documentation (by tomhukins)
148167
149 0.022 2015/05/22
168 0.022 2015-05-22
150169 - new: Crypt::PK::ECC+RSA export_key_jwk() - exporting JWK format
151170 - new: Crypt::Digest::SHA512_224
152171 - new: Crypt::Digest::SHA512_256
160179 - libtommath updated to the latest develop branch, commit 0fd5e6c17f Dec 11 14:59:35 2014 +0100
161180 - documentation fixes
162181
163 0.021 2014/01/23
182 0.021 2014-01-23
164183 - fixed asm(...) related compiler failures
165184 - dsa_encrypt_key small correction
166185 - optimized ecc_encrypt_key
167186
168 0.020 2014/01/18
187 0.020 2014-01-18
169188 - INCOMPATIBLE CHANGE: huge redesign of Crypt::PK::ECC
170189 - ECC now supports curves y^2 = x^3 + a*x + b
171190 - ECC you can use custom curves
173192 - enabling compile options ASM + ECC_TIMING_RESISTANT
174193 - added many test vectors (RSA, DSA, EC) for interoperability with openssl
175194
176 0.019 2013/10/20
195 0.019 2013-10-20
177196 - fixed broken CAMELLIA implementation
178197
179 0.018 2013/10/18
198 0.018 2013-10-18
180199 - DSA: make_key + sign_hash fixes
181200
182 0.017 2013/09/24
201 0.017 2013-09-24
183202 - lowering MIME::Base64 version requirement
184203 - support for import/export of password protected RSA/DSA keys
185204 - RSA: added - export_key_pem('public_x509')
187206 - added openssl test vectors
188207 - fixed compiler warnings (RSA/DSA/ECC/DH)
189208
190 0.016 2013/09/15
209 0.016 2013-09-15
191210 - added missing test for key2hash, sign_hash, verify_hash
192211 - fixed build failures on VC6
193212
194 0.015 2013/09/12
213 0.015 2013-09-12
195214 - only documentation fixes
196215
197 0.014 2013/09/11
216 0.014 2013-09-11
198217 - Crypt::Digest::NNN + Crypt::Mac::NNN - can produce Base64-URL-Safe encoded digest/mac
199218 - Crypt::PRNG + Crypt::PRNG::NNN - Base64-URL-Safe encoded random bytes (random_bytes_b64u/bytes_b64u)
200219 - Crypt::PK::RSA/DSA/DH/ECC - sign/verify replaced by sign_message/verify_message + sign_hash/verify_hash
201220 - Crypt::PK::RSA/DSA/DH/ECC - new method key2hash
202221 - documentation fixes
203222
204 0.013 2013/08/28
223 0.013 2013-08-28
205224 - DSA/RSA/ECC/DH - importing keys from string changed - now: $pk->import_key(\$buffer_with_key)
206225 - DSA/RSA/ECC/DH - size() and is_private() now return undef if no key loaded
207226 - improved RSA doc
208227
209 0.012 2013/06/17
228 0.012 2013-06-17
210229 - README, LICENSE etc. to improve CPANTS score
211230 - somehow works with perl 5.6.2
212231
213 0.011 2013/06/15
232 0.011 2013-06-15
214233 - fixing various compiler warnings
215234
216 0.009 2013/05/19
235 0.009 2013-05-19
217236 - doc fixes
218237 - requires perl 5.8.8 or higher
219238 - INCOMPATIBILITY: all digest related 'xxx_base64' functions renamed to 'xxx_b64'
220239
221 0.008 2013/05/02
240 0.008 2013-05-02
222241 - fixed prng test failures
223242 - Crypt::Digest::* croaks with the "real caller" (not a nice solution)
224243
225 0.007 2013/04/23
244 0.007 2013-04-23
226245 - Crypt::PRNG supports add_entropy() - without params
227246 - Crypt::PRNG fork-safe & thread-safe
228247 - random_string has default $len = 20
229248 - doc fixes
230249 - cpan tester failure fix for pk_dsa.t
231250
232 0.006 2013/04/19
251 0.006 2013-04-19
233252 - added Crypt::KeyDerivation
234253 - Win64 compatibility
235254
236 0.005 2013/04/18
255 0.005 2013-04-18
237256 - added Crypt::PRNG::Fortuna|RC4|Sober128|Yarrow
238257 - added Crypt::PK::RSA|DSA|ECC|DH
239258
240 0.004 2013/04/16
259 0.004 2013-04-16
241260 - removing illegal Crypt::Random
242261
243 0.003 2013/04/16
262 0.003 2013-04-16
244263 - added Crypt::Mode::CBC|CFB|CTR|ECB|OFB
245264 - added Crypt::AuthEnc::CCM|EAX|GCM|OCB
246265
247 0.002 2013/04/11
266 0.002 2013-04-11
248267 - first release on CPAN
481481 {
482482 STRLEN len, i = 0;
483483 unsigned char *out_data, *in_data;
484 int rv;
485484
486485 if (!SvPOK(in)) XSRETURN_UNDEF;
487486 in_data = (unsigned char *) SvPVbyte(in, len);
508507 {
509508 STRLEN len, i = 0;
510509 unsigned char *out_data, *in_data;
511 int rv;
512510
513511 if (!SvPOK(in)) XSRETURN_UNDEF;
514512 in_data = (unsigned char *) SvPVbyte(in, len);
529527 OUTPUT:
530528 RETVAL
531529
530 SV *
531 CryptX__radix_to_bin(char *in, int radix)
532 CODE:
533 {
534 STRLEN len;
535 unsigned char *out_data;
536 mp_int mpi;
537
538 if (in == NULL || strlen(in) == 0) XSRETURN_UNDEF;
539
540 if (mp_init(&mpi) != CRYPT_OK) XSRETURN_UNDEF;
541
542 if (mp_read_radix(&mpi, in, radix) == CRYPT_OK) {
543 len = mp_unsigned_bin_size(&mpi);
544 RETVAL = NEWSV(0, len);
545 SvPOK_only(RETVAL);
546 SvCUR_set(RETVAL, len);
547 out_data = (unsigned char *)SvPV_nolen(RETVAL);
548 mp_to_unsigned_bin(&mpi, out_data);
549 mp_clear(&mpi);
550 }
551 else {
552 XSRETURN_UNDEF;
553 }
554 }
555 OUTPUT:
556 RETVAL
557
558 SV *
559 CryptX__bin_to_radix(SV *in, int radix)
560 CODE:
561 {
562 STRLEN len;
563 unsigned char *in_data;
564 char *out_data;
565 mp_int mpi, tmp;
566 mp_digit d;
567 int digits = 0;
568
569 if (!SvPOK(in) || radix < 2 || radix > 64) XSRETURN_UNDEF;
570 in_data = (unsigned char *) SvPVbyte(in, len);
571 if (len == 0) XSRETURN_UNDEF;
572
573 mp_init(&mpi);
574 if (mp_read_unsigned_bin(&mpi, in_data, len) == CRYPT_OK) {
575 mp_init_copy(&tmp, &mpi);
576 while (mp_iszero(&tmp) == MP_NO) {
577 mp_div_d(&tmp, (mp_digit)radix, &tmp, &d);
578 digits++;
579 }
580 mp_clear(&tmp);
581
582 RETVAL = NEWSV(0, digits + 1);
583 SvPOK_only(RETVAL);
584 out_data = SvPV_nolen(RETVAL);
585 mp_toradix(&mpi, out_data, radix);
586 SvCUR_set(RETVAL, digits);
587 mp_clear(&mpi);
588 }
589 else {
590 XSRETURN_UNDEF;
591 }
592 }
593 OUTPUT:
594 RETVAL
595
596 SV *
597 CryptX__encode_b32(SV *bytes, unsigned idx)
598 CODE:
599 {
600 STRLEN inlen, outlen, i, leven;
601 unsigned char *out, *in, *codes;
602 char *alphabet[] = {
603 "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", /* rfc4648 */
604 "0123456789ABCDEFGHIJKLMNOPQRSTUV", /* base32hex */
605 "ybndrfg8ejkmcpqxot1uwisza345h769", /* zbase32 */
606 "0123456789ABCDEFGHJKMNPQRSTVWXYZ" /* crockford */
607 };
608
609 if (!SvOK(bytes)) {
610 /* for undefined input return "" (empty string) */
611 RETVAL = newSVpv("", 0);
612 }
613 else {
614 if (!SvPOK(bytes) || idx > 3) XSRETURN_UNDEF; /* error */
615 in = (unsigned char *) SvPVbyte(bytes, inlen);
616 if (in == NULL) XSRETURN_UNDEF; /* error */
617 if (inlen == 0) {
618 RETVAL = newSVpv("", 0);
619 }
620 else {
621 codes = (unsigned char*)alphabet[idx];
622 outlen = (8 * inlen + 4) / 5;
623 RETVAL = NEWSV(0, outlen);
624 SvPOK_only(RETVAL);
625 SvCUR_set(RETVAL, outlen);
626 out = (unsigned char *)SvPV_nolen(RETVAL);
627
628 leven = 5 * (inlen / 5);
629 for (i = 0; i < leven; i += 5) {
630 *out++ = codes[(in[0] >> 3) & 0x1F];
631 *out++ = codes[(((in[0] & 0x7) << 2) + (in[1] >> 6)) & 0x1F];
632 *out++ = codes[(in[1] >> 1) & 0x1F];
633 *out++ = codes[(((in[1] & 0x1) << 4) + (in[2] >> 4)) & 0x1F];
634 *out++ = codes[(((in[2] & 0xF) << 1) + (in[3] >> 7)) & 0x1F];
635 *out++ = codes[(in[3] >> 2) & 0x1F];
636 *out++ = codes[(((in[3] & 0x3) << 3) + (in[4] >> 5)) & 0x1F];
637 *out++ = codes[in[4] & 0x1F];
638 in += 5;
639 }
640 if (i < inlen) {
641 unsigned a = in[0];
642 unsigned b = (i+1 < inlen) ? in[1] : 0;
643 unsigned c = (i+2 < inlen) ? in[2] : 0;
644 unsigned d = (i+3 < inlen) ? in[3] : 0;
645 *out++ = codes[(a >> 3) & 0x1F];
646 *out++ = codes[(((a & 0x7) << 2) + (b >> 6)) & 0x1F];
647 if (i+1 < inlen) {
648 *out++ = codes[(b >> 1) & 0x1F];
649 *out++ = codes[(((b & 0x1) << 4) + (c >> 4)) & 0x1F];
650 }
651 if (i+2 < inlen) {
652 *out++ = codes[(((c & 0xF) << 1) + (d >> 7)) & 0x1F];
653 *out++ = codes[(d >> 2) & 0x1F];
654 }
655 if (i+3 < inlen) {
656 *out++ = codes[((d & 0x3) << 3) & 0x1F];
657 }
658 }
659 }
660 }
661 }
662 OUTPUT:
663 RETVAL
664
665 SV *
666 CryptX__decode_b32(SV *base32, unsigned idx)
667 CODE:
668 {
669 STRLEN x, inlen, outlen;
670 int y = 0;
671 ulong64 t = 0;
672 unsigned char c, *in, *out, *map;
673 unsigned char tables[4][43] = {
674 { /* rfc4648 ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 */
675 99/*0*/,99/*1*/,26/*2*/,27/*3*/,28/*4*/,29/*5*/,30/*6*/,31/*7*/,99/*8*/,99/*9*/,
676 99/*:*/,99/*;*/,99/*<*/,99/*=*/,99/*>*/,99/*?*/,99/*@*/,
677 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/, 7/*H*/, 8/*I*/, 9/*J*/,10/*K*/,11/*L*/,12/*M*/,
678 13/*N*/,14/*O*/,15/*P*/,16/*Q*/,17/*R*/,18/*S*/,19/*T*/,20/*U*/,21/*V*/,22/*W*/,23/*X*/,24/*Y*/,25/*Z*/
679 },
680 { /* base32hex 0123456789ABCDEFGHIJKLMNOPQRSTUV */
681 0/*0*/, 1/*1*/, 2/*2*/, 3/*3*/, 4/*4*/, 5/*5*/, 6/*6*/, 7/*7*/, 8/*8*/, 9/*9*/,
682 99/*:*/,99/*;*/,99/*<*/,99/*=*/,99/*>*/,99/*?*/,99/*@*/,
683 10/*A*/,11/*B*/,12/*C*/,13/*D*/,14/*E*/,15/*F*/,16/*G*/,17/*H*/,18/*I*/,19/*J*/,20/*K*/,21/*L*/,22/*M*/,
684 23/*N*/,24/*O*/,25/*P*/,26/*Q*/,27/*R*/,28/*S*/,29/*T*/,30/*U*/,31/*V*/,99/*W*/,99/*X*/,99/*Y*/,99/*Z*/
685 },
686 { /* zbase32 YBNDRFG8EJKMCPQXOT1UWISZA345H769 */
687 99/*0*/,18/*1*/,99/*2*/,25/*3*/,26/*4*/,27/*5*/,30/*6*/,29/*7*/, 7/*8*/,31/*9*/,
688 99/*:*/,99/*;*/,99/*<*/,99/*=*/,99/*>*/,99/*?*/,99/*@*/,
689 24/*A*/, 1/*B*/,12/*C*/, 3/*D*/, 8/*E*/, 5/*F*/, 6/*G*/,28/*H*/,21/*I*/, 9/*J*/,10/*K*/,99/*L*/,11/*M*/,
690 2/*N*/,16/*O*/,13/*P*/,14/*Q*/, 4/*R*/,22/*S*/,17/*T*/,19/*U*/,99/*V*/,20/*W*/,15/*X*/, 0/*Y*/,23/*Z*/
691 },
692 { /* crockford 0123456789ABCDEFGHJKMNPQRSTVWXYZ + O=>0 + IL=>1 */
693 0/*0*/, 1/*1*/, 2/*2*/, 3/*3*/, 4/*4*/, 5/*5*/, 6/*6*/, 7/*7*/, 8/*8*/, 9/*9*/,
694 99/*:*/,99/*;*/,99/*<*/,99/*=*/,99/*>*/,99/*?*/,99/*@*/,
695 10/*A*/,11/*B*/,12/*C*/,13/*D*/,14/*E*/,15/*F*/,16/*G*/,17/*H*/, 1/*I*/,18/*J*/,19/*K*/, 1/*L*/,20/*M*/,
696 21/*N*/, 0/*O*/,22/*P*/,23/*Q*/,24/*R*/,25/*S*/,26/*T*/,99/*U*/,27/*V*/,28/*W*/,29/*X*/,30/*Y*/,31/*Z*/
697 }
698 };
699
700 if (!SvOK(base32)) {
701 /* for undefined input return "" (empty string) */
702 RETVAL = newSVpv("", 0);
703 }
704 else {
705 if (!SvPOK(base32) || idx > 3) XSRETURN_UNDEF; /* error */
706 in = (unsigned char *) SvPVbyte(base32, inlen);
707 if (in == NULL) XSRETURN_UNDEF; /* error */
708
709 while (inlen>0 && in[inlen-1] == '=') inlen--;
710 if (inlen == 0) {
711 RETVAL = newSVpv("", 0);
712 }
713 else {
714 x = inlen % 8;
715 if (x == 1 || x == 3 || x == 6) XSRETURN_UNDEF; /* error */
716 outlen = (inlen * 5) / 8;
717 RETVAL = NEWSV(0, outlen);
718 SvPOK_only(RETVAL);
719 SvCUR_set(RETVAL, outlen);
720 out = (unsigned char *)SvPV_nolen(RETVAL);
721 map = tables[idx];
722 for (x = 0; x < inlen; x++) {
723 c = in[x];
724 /* convert to upper case */
725 if ((c >= 'a') && (c <= 'z')) c -= 32;
726 /* '0' = 48 .. 'Z' = 90 */
727 if (c < 48 || c > 90 || map[c-48] > 31) XSRETURN_UNDEF; /* error */
728 t = (t<<5)|map[c-48];
729 if (++y == 8) {
730 *out++ = (unsigned char)((t>>32) & 255);
731 *out++ = (unsigned char)((t>>24) & 255);
732 *out++ = (unsigned char)((t>>16) & 255);
733 *out++ = (unsigned char)((t>> 8) & 255);
734 *out++ = (unsigned char)( t & 255);
735 y = 0;
736 t = 0;
737 }
738 }
739 if (y > 0) {
740 t = t << (5 * (8 - y));
741 if (y >= 2) *out++ = (unsigned char)((t>>32) & 255);
742 if (y >= 4) *out++ = (unsigned char)((t>>24) & 255);
743 if (y >= 5) *out++ = (unsigned char)((t>>16) & 255);
744 if (y >= 7) *out++ = (unsigned char)((t>> 8) & 255);
745 }
746 }
747 }
748 }
749 OUTPUT:
750 RETVAL
751
752 SV *
753 CryptX__ltc_build_settings()
754 CODE:
755 RETVAL = newSVpv(crypt_build_settings, 0);
756 OUTPUT:
757 RETVAL
758
759 SV *
760 CryptX__ltc_mp_name()
761 CODE:
762 RETVAL = newSVpv(ltc_mp.name, 0);
763 OUTPUT:
764 RETVAL
765
766 int
767 CryptX__ltc_mp_bits_per_digit()
768 CODE:
769 RETVAL = ltc_mp.bits_per_digit;
770 OUTPUT:
771 RETVAL
772
532773 ###############################################################################
533774
534775 INCLUDE: inc/CryptX_Digest.xs.inc
535 INCLUDE: inc/CryptX_Digest_SHAKE.xs.inc
776 INCLUDE: inc/CryptX_Digest_SHAKE.xs.inc
536777 INCLUDE: inc/CryptX_Cipher.xs.inc
537778
538779 INCLUDE: inc/CryptX_Checksum_Adler32.xs.inc
137137 META.json
138138 META.yml
139139 ppport.h
140 README
140 README.md
141141 src/ltc/ciphers/aes/aes.c
142142 src/ltc/ciphers/aes/aes_tab.c
143143 src/ltc/ciphers/anubis.c
200200 src/ltc/encauth/ocb3/ocb3_encrypt_authenticate_memory.c
201201 src/ltc/encauth/ocb3/ocb3_encrypt_last.c
202202 src/ltc/encauth/ocb3/ocb3_init.c
203 src/ltc/encauth/ocb3/ocb3_int_aad_add_block.c
204 src/ltc/encauth/ocb3/ocb3_int_calc_offset_zero.c
205203 src/ltc/encauth/ocb3/ocb3_int_ntz.c
206204 src/ltc/encauth/ocb3/ocb3_int_xor_blocks.c
207205 src/ltc/hashes/blake2b.c
292290 src/ltc/math/fp/ltc_ecc_fp_mulmod.c
293291 src/ltc/math/ltm_desc.c
294292 src/ltc/math/multi.c
293 src/ltc/math/radix_to_bin.c
295294 src/ltc/math/rand_bn.c
296295 src/ltc/math/rand_prime.c
297296 src/ltc/math/tfm_desc.c
299298 src/ltc/misc/base64/base64_decode.c
300299 src/ltc/misc/base64/base64_encode.c
301300 src/ltc/misc/burn_stack.c
301 src/ltc/misc/compare_testvector.c
302302 src/ltc/misc/crc32.c
303303 src/ltc/misc/crypt/crypt.c
304304 src/ltc/misc/crypt/crypt_argchk.c
305305 src/ltc/misc/crypt/crypt_cipher_descriptor.c
306306 src/ltc/misc/crypt/crypt_cipher_is_valid.c
307 src/ltc/misc/crypt/crypt_constants.c
307308 src/ltc/misc/crypt/crypt_find_cipher.c
308309 src/ltc/misc/crypt/crypt_find_cipher_any.c
309310 src/ltc/misc/crypt/crypt_find_cipher_id.c
319320 src/ltc/misc/crypt/crypt_ltc_mp_descriptor.c
320321 src/ltc/misc/crypt/crypt_prng_descriptor.c
321322 src/ltc/misc/crypt/crypt_prng_is_valid.c
323 src/ltc/misc/crypt/crypt_prng_rng_descriptor.c
324 src/ltc/misc/crypt/crypt_register_all_ciphers.c
325 src/ltc/misc/crypt/crypt_register_all_hashes.c
326 src/ltc/misc/crypt/crypt_register_all_prngs.c
322327 src/ltc/misc/crypt/crypt_register_cipher.c
323328 src/ltc/misc/crypt/crypt_register_hash.c
324329 src/ltc/misc/crypt/crypt_register_prng.c
330 src/ltc/misc/crypt/crypt_sizes.c
325331 src/ltc/misc/crypt/crypt_unregister_cipher.c
326332 src/ltc/misc/crypt/crypt_unregister_hash.c
327333 src/ltc/misc/crypt/crypt_unregister_prng.c
396402 src/ltc/pk/asn1/der/sequence/der_encode_subject_public_key_info.c
397403 src/ltc/pk/asn1/der/sequence/der_length_sequence.c
398404 src/ltc/pk/asn1/der/sequence/der_sequence_free.c
405 src/ltc/pk/asn1/der/sequence/der_sequence_shrink.c
399406 src/ltc/pk/asn1/der/set/der_encode_set.c
400407 src/ltc/pk/asn1/der/set/der_encode_setof.c
401408 src/ltc/pk/asn1/der/short_integer/der_decode_short_integer.c
410417 src/ltc/pk/asn1/der/utf8/der_encode_utf8_string.c
411418 src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c
412419 src/ltc/pk/dh/dh.c
413 src/ltc/pk/dh/dh_static.c
414 src/ltc/pk/dh/dh_static.h
415 src/ltc/pk/dh/dh_sys.c
420 src/ltc/pk/dh/dh_check_pubkey.c
421 src/ltc/pk/dh/dh_export.c
422 src/ltc/pk/dh/dh_export_key.c
423 src/ltc/pk/dh/dh_free.c
424 src/ltc/pk/dh/dh_generate_key.c
425 src/ltc/pk/dh/dh_import.c
426 src/ltc/pk/dh/dh_set.c
427 src/ltc/pk/dh/dh_set_pg_dhparam.c
428 src/ltc/pk/dh/dh_shared_secret.c
416429 src/ltc/pk/dsa/dsa_decrypt_key.c
417430 src/ltc/pk/dsa/dsa_encrypt_key.c
418431 src/ltc/pk/dsa/dsa_export.c
419432 src/ltc/pk/dsa/dsa_free.c
433 src/ltc/pk/dsa/dsa_generate_key.c
434 src/ltc/pk/dsa/dsa_generate_pqg.c
420435 src/ltc/pk/dsa/dsa_import.c
421 src/ltc/pk/dsa/dsa_import_radix.c
422436 src/ltc/pk/dsa/dsa_make_key.c
437 src/ltc/pk/dsa/dsa_set.c
438 src/ltc/pk/dsa/dsa_set_pqg_dsaparam.c
423439 src/ltc/pk/dsa/dsa_shared_secret.c
424440 src/ltc/pk/dsa/dsa_sign_hash.c
425441 src/ltc/pk/dsa/dsa_verify_hash.c
479495 src/ltc/pk/rsa/rsa_get_size.c
480496 src/ltc/pk/rsa/rsa_import.c
481497 src/ltc/pk/rsa/rsa_import_pkcs8.c
482 src/ltc/pk/rsa/rsa_import_radix.c
483498 src/ltc/pk/rsa/rsa_import_x509.c
484499 src/ltc/pk/rsa/rsa_make_key.c
500 src/ltc/pk/rsa/rsa_set.c
485501 src/ltc/pk/rsa/rsa_sign_hash.c
486502 src/ltc/pk/rsa/rsa_sign_saltlen_get.c
487503 src/ltc/pk/rsa/rsa_verify_hash.c
764780 t/data/openssl_ec1.pub.pem
765781 t/data/openssl_ec1.pubc.der
766782 t/data/openssl_ec1.pubc.pem
783 t/data/openssl_rsa-x509.der
784 t/data/openssl_rsa-x509.pem
767785 t/data/openssl_rsa1.der
768786 t/data/openssl_rsa1.pem
769787 t/data/openssl_rsa1.pubonly.der
925943 t/prng_sober128.t
926944 t/prng_yarrow.t
927945 t/sshkey.t
946 t/wycheproof.t
947 t/wycheproof/aes_gcm_test.json
948 t/wycheproof/dsa_test.json
949 t/wycheproof/ecdh_webcrypto_test.json
950 t/wycheproof/ecdsa_test.json
951 t/wycheproof/ecdsa_webcrypto_test.json
952 t/wycheproof/rsa_signature_test.json
928953 typemap
33 "Karel Miko"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010",
6 "generated_by" : "ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010",
77 "license" : [
88 "perl_5"
99 ],
1010 "meta-spec" : {
1111 "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
12 "version" : "2"
12 "version" : 2
1313 },
1414 "name" : "CryptX",
1515 "no_index" : {
4444 "url" : "https://github.com/DCIT/perl-CryptX"
4545 }
4646 },
47 "version" : "0.048",
48 "x_serialization_backend" : "JSON::PP version 2.27400"
47 "version" : "0.054",
48 "x_serialization_backend" : "JSON::PP version 2.94"
4949 }
66 configure_requires:
77 ExtUtils::MakeMaker: '0'
88 dynamic_config: 1
9 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
9 generated_by: 'ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010'
1010 license: perl
1111 meta-spec:
1212 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2121 resources:
2222 bugtracker: https://github.com/DCIT/perl-CryptX/issues
2323 repository: https://github.com/DCIT/perl-CryptX
24 version: '0.048'
24 version: '0.054'
2525 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
1010 glob('src/ltc/*/*/*/*/*.c'),
1111 );
1212 my $myextlib = "src/liballinone$Config{lib_ext}";
13 my $mycflags = "$Config{cccdlflags} $Config{ccflags} $Config{optimize} -Iltm -Iltc/headers -DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC";
13 my $mycflags = "$Config{ccflags} $Config{cccdlflags} $Config{optimize}";
1414
1515 #FIX: gcc with -flto is a trouble maker see https://github.com/DCIT/perl-CryptX/issues/32
1616 $mycflags =~ s/-flto\b//g;
17
18 #FIX: avoid -Wwrite-strings -Wcast-qual -pedantic -pedantic-errors -ansi -std=c89
19 $mycflags =~ s/-pedantic\b//g;
20 $mycflags =~ s/-pedantic-errors\b//g;
21 $mycflags =~ s/-std=c89\b//g;
22 $mycflags =~ s/-ansi\b//g;
23 $mycflags =~ s/-Wwrite-strings\b//g;
24 $mycflags =~ s/-Wcast-qual\b//g;
1725
1826 #FIX: avoid "ar: fatal: Numeric group ID too large" see https://github.com/DCIT/perl-CryptX/issues/33
1927 my $myarflags = '$(AR_STATIC_ARGS)';
2028 if ($^O ne 'MSWin32' && $Config{ar}) {
2129 # for ar's "deterministic mode" we need GNU binutils 2.20+ (2009-10-16)
22 my $arver = `$Config{ar} --version`;
30 my $arver = `$Config{ar} --version 2>/dev/null`;
2331 my ($maj, $min) = $arver =~ /^GNU ar [^\d]*(\d)\.(\d+)\.\d+/s;
2432 $myarflags = 'rcD' if ($maj && $min && $maj >= 2 && $min >= 20) || $arver=~ /^BSD ar /;
2533 }
3240 MIN_PERL_VERSION => '5.006',
3341 LICENSE => 'perl_5',
3442 META_MERGE => { resources => { repository => 'https://github.com/DCIT/perl-CryptX', bugtracker => 'https://github.com/DCIT/perl-CryptX/issues' } },
35 DEFINE => '-DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC',
36 INC => '-Isrc/ltc/headers -Isrc/ltm',
37 LIBS => [''],
38 MYEXTLIB => $myextlib,
39 clean => { 'FILES' => join(' ', @myobjs, $myextlib) },
43 dist => { 'PREOP' => 'perldoc -u lib/CryptX.pm | pod2markdown > README.md' },
44 ($ENV{CRYPTX_CFLAGS} || $ENV{CRYPTX_LDFLAGS})
45 ?
46 (
47 # e.g. CRYPTX_LDFLAGS='-L/usr/local/lib -ltommath -ltomcrypt' CRYPTX_CFLAGS='-DLTM_DESC -I/usr/local/include' perl Makefile.PL
48 INC => $ENV{CRYPTX_CFLAGS},
49 LIBS => [ $ENV{CRYPTX_LDFLAGS} ],
50 )
51 :
52 (
53 # bundled libtomcrypt + libtommath
54 INC => '-DLTM_DESC -Isrc/ltc/headers -Isrc/ltm',
55 MYEXTLIB => $myextlib,
56 clean => { 'FILES' => join(' ', @myobjs, $myextlib) },
57 )
4058 );
4159
4260 my $eumm_ver = eval $ExtUtils::MakeMaker::VERSION;
+0
-68
README less more
0 NAME
1 CryptX - Crypto toolkit (self-contained no external libraries needed)
2
3 DESCRIPTION
4 Cryptography in CryptX is based on
5 <https://github.com/libtom/libtomcrypt>
6
7 Currently available modules:
8
9 * Ciphers - see Crypt::Cipher and related modules
10
11 Crypt::Cipher::AES, Crypt::Cipher::Anubis, Crypt::Cipher::Blowfish,
12 Crypt::Cipher::Camellia, Crypt::Cipher::CAST5, Crypt::Cipher::DES,
13 Crypt::Cipher::DES_EDE, Crypt::Cipher::KASUMI,
14 Crypt::Cipher::Khazad, Crypt::Cipher::MULTI2,
15 Crypt::Cipher::Noekeon, Crypt::Cipher::RC2, Crypt::Cipher::RC5,
16 Crypt::Cipher::RC6, Crypt::Cipher::SAFERP,
17 Crypt::Cipher::SAFER_K128, Crypt::Cipher::SAFER_K64,
18 Crypt::Cipher::SAFER_SK128, Crypt::Cipher::SAFER_SK64,
19 Crypt::Cipher::SEED, Crypt::Cipher::Skipjack,
20 Crypt::Cipher::Twofish, Crypt::Cipher::XTEA
21
22 * Block cipher modes
23
24 Crypt::Mode::CBC, Crypt::Mode::CFB, Crypt::Mode::CTR,
25 Crypt::Mode::ECB, Crypt::Mode::OFB
26
27 * Authenticated encryption modes
28
29 Crypt::AuthEnc::CCM, Crypt::AuthEnc::EAX, Crypt::AuthEnc::GCM,
30 Crypt::AuthEnc::OCB
31
32 * Hash Functions - see Crypt::Digest and related modules
33
34 Crypt::Digest::CHAES, Crypt::Digest::MD2, Crypt::Digest::MD4,
35 Crypt::Digest::MD5, Crypt::Digest::RIPEMD128,
36 Crypt::Digest::RIPEMD160, Crypt::Digest::RIPEMD256,
37 Crypt::Digest::RIPEMD320, Crypt::Digest::SHA1,
38 Crypt::Digest::SHA224, Crypt::Digest::SHA256, Crypt::Digest::SHA384,
39 Crypt::Digest::SHA512, Crypt::Digest::SHA512_224,
40 Crypt::Digest::SHA512_256, Crypt::Digest::Tiger192,
41 Crypt::Digest::Whirlpool
42
43 * Message Authentication Codes
44
45 Crypt::Mac::F9, Crypt::Mac::HMAC, Crypt::Mac::OMAC,
46 Crypt::Mac::Pelican, Crypt::Mac::PMAC, Crypt::Mac::XCBC
47
48 * Public key cryptography
49
50 Crypt::PK::RSA, Crypt::PK::DSA, Crypt::PK::ECC, Crypt::PK::DH
51
52 * Cryptographically secure random number generators
53
54 Crypt::PRNG, Crypt::PRNG::Fortuna, Crypt::PRNG::Yarrow,
55 Crypt::PRNG::RC4, Crypt::PRNG::Sober128
56
57 * Key derivation functions - PBKDF1, PBKFD2 and HKDF
58
59 Crypt::KeyDerivation
60
61 LICENSE
62 This program is free software; you can redistribute it and/or modify it
63 under the same terms as Perl itself.
64
65 COPYRIGHT
66 Copyright (c) 2013-2015 DCIT, a.s. <http://www.dcit.cz> / Karel Miko
67
0 # NAME
1
2 CryptX - Crypto toolkit (self-contained no external libraries needed)
3
4 # DESCRIPTION
5
6 Cryptography in CryptX is based on [https://github.com/libtom/libtomcrypt](https://github.com/libtom/libtomcrypt)
7
8 Currently available modules:
9
10 - Ciphers - see [Crypt::Cipher](https://metacpan.org/pod/Crypt::Cipher) and related modules
11
12 [Crypt::Cipher::AES](https://metacpan.org/pod/Crypt::Cipher::AES), [Crypt::Cipher::Anubis](https://metacpan.org/pod/Crypt::Cipher::Anubis), [Crypt::Cipher::Blowfish](https://metacpan.org/pod/Crypt::Cipher::Blowfish), [Crypt::Cipher::Camellia](https://metacpan.org/pod/Crypt::Cipher::Camellia), [Crypt::Cipher::CAST5](https://metacpan.org/pod/Crypt::Cipher::CAST5), [Crypt::Cipher::DES](https://metacpan.org/pod/Crypt::Cipher::DES),
13 [Crypt::Cipher::DES\_EDE](https://metacpan.org/pod/Crypt::Cipher::DES_EDE), [Crypt::Cipher::KASUMI](https://metacpan.org/pod/Crypt::Cipher::KASUMI), [Crypt::Cipher::Khazad](https://metacpan.org/pod/Crypt::Cipher::Khazad), [Crypt::Cipher::MULTI2](https://metacpan.org/pod/Crypt::Cipher::MULTI2), [Crypt::Cipher::Noekeon](https://metacpan.org/pod/Crypt::Cipher::Noekeon), [Crypt::Cipher::RC2](https://metacpan.org/pod/Crypt::Cipher::RC2),
14 [Crypt::Cipher::RC5](https://metacpan.org/pod/Crypt::Cipher::RC5), [Crypt::Cipher::RC6](https://metacpan.org/pod/Crypt::Cipher::RC6), [Crypt::Cipher::SAFERP](https://metacpan.org/pod/Crypt::Cipher::SAFERP), [Crypt::Cipher::SAFER\_K128](https://metacpan.org/pod/Crypt::Cipher::SAFER_K128), [Crypt::Cipher::SAFER\_K64](https://metacpan.org/pod/Crypt::Cipher::SAFER_K64), [Crypt::Cipher::SAFER\_SK128](https://metacpan.org/pod/Crypt::Cipher::SAFER_SK128),
15 [Crypt::Cipher::SAFER\_SK64](https://metacpan.org/pod/Crypt::Cipher::SAFER_SK64), [Crypt::Cipher::SEED](https://metacpan.org/pod/Crypt::Cipher::SEED), [Crypt::Cipher::Skipjack](https://metacpan.org/pod/Crypt::Cipher::Skipjack), [Crypt::Cipher::Twofish](https://metacpan.org/pod/Crypt::Cipher::Twofish), [Crypt::Cipher::XTEA](https://metacpan.org/pod/Crypt::Cipher::XTEA)
16
17 - Block cipher modes
18
19 [Crypt::Mode::CBC](https://metacpan.org/pod/Crypt::Mode::CBC), [Crypt::Mode::CFB](https://metacpan.org/pod/Crypt::Mode::CFB), [Crypt::Mode::CTR](https://metacpan.org/pod/Crypt::Mode::CTR), [Crypt::Mode::ECB](https://metacpan.org/pod/Crypt::Mode::ECB), [Crypt::Mode::OFB](https://metacpan.org/pod/Crypt::Mode::OFB)
20
21 - Stream ciphers
22
23 [Crypt::Stream::RC4](https://metacpan.org/pod/Crypt::Stream::RC4), [Crypt::Stream::ChaCha](https://metacpan.org/pod/Crypt::Stream::ChaCha), [Crypt::Stream::Sober128](https://metacpan.org/pod/Crypt::Stream::Sober128)
24
25 - Authenticated encryption modes
26
27 [Crypt::AuthEnc::CCM](https://metacpan.org/pod/Crypt::AuthEnc::CCM), [Crypt::AuthEnc::EAX](https://metacpan.org/pod/Crypt::AuthEnc::EAX), [Crypt::AuthEnc::GCM](https://metacpan.org/pod/Crypt::AuthEnc::GCM), [Crypt::AuthEnc::OCB](https://metacpan.org/pod/Crypt::AuthEnc::OCB), [Crypt::AuthEnc::ChaCha20Poly1305](https://metacpan.org/pod/Crypt::AuthEnc::ChaCha20Poly1305)
28
29 - Hash Functions - see [Crypt::Digest](https://metacpan.org/pod/Crypt::Digest) and related modules
30
31 [Crypt::Digest::BLAKE2b\_160](https://metacpan.org/pod/Crypt::Digest::BLAKE2b_160), [Crypt::Digest::BLAKE2b\_256](https://metacpan.org/pod/Crypt::Digest::BLAKE2b_256), [Crypt::Digest::BLAKE2b\_384](https://metacpan.org/pod/Crypt::Digest::BLAKE2b_384), [Crypt::Digest::BLAKE2b\_512](https://metacpan.org/pod/Crypt::Digest::BLAKE2b_512),
32 [Crypt::Digest::BLAKE2s\_128](https://metacpan.org/pod/Crypt::Digest::BLAKE2s_128), [Crypt::Digest::BLAKE2s\_160](https://metacpan.org/pod/Crypt::Digest::BLAKE2s_160), [Crypt::Digest::BLAKE2s\_224](https://metacpan.org/pod/Crypt::Digest::BLAKE2s_224), [Crypt::Digest::BLAKE2s\_256](https://metacpan.org/pod/Crypt::Digest::BLAKE2s_256),
33 [Crypt::Digest::CHAES](https://metacpan.org/pod/Crypt::Digest::CHAES), [Crypt::Digest::MD2](https://metacpan.org/pod/Crypt::Digest::MD2), [Crypt::Digest::MD4](https://metacpan.org/pod/Crypt::Digest::MD4), [Crypt::Digest::MD5](https://metacpan.org/pod/Crypt::Digest::MD5), [Crypt::Digest::RIPEMD128](https://metacpan.org/pod/Crypt::Digest::RIPEMD128), [Crypt::Digest::RIPEMD160](https://metacpan.org/pod/Crypt::Digest::RIPEMD160),
34 [Crypt::Digest::RIPEMD256](https://metacpan.org/pod/Crypt::Digest::RIPEMD256), [Crypt::Digest::RIPEMD320](https://metacpan.org/pod/Crypt::Digest::RIPEMD320), [Crypt::Digest::SHA1](https://metacpan.org/pod/Crypt::Digest::SHA1), [Crypt::Digest::SHA224](https://metacpan.org/pod/Crypt::Digest::SHA224), [Crypt::Digest::SHA256](https://metacpan.org/pod/Crypt::Digest::SHA256), [Crypt::Digest::SHA384](https://metacpan.org/pod/Crypt::Digest::SHA384),
35 [Crypt::Digest::SHA512](https://metacpan.org/pod/Crypt::Digest::SHA512), [Crypt::Digest::SHA512\_224](https://metacpan.org/pod/Crypt::Digest::SHA512_224), [Crypt::Digest::SHA512\_256](https://metacpan.org/pod/Crypt::Digest::SHA512_256), [Crypt::Digest::Tiger192](https://metacpan.org/pod/Crypt::Digest::Tiger192), [Crypt::Digest::Whirlpool](https://metacpan.org/pod/Crypt::Digest::Whirlpool),
36 [Crypt::Digest::SHA3\_224](https://metacpan.org/pod/Crypt::Digest::SHA3_224), [Crypt::Digest::SHA3\_256](https://metacpan.org/pod/Crypt::Digest::SHA3_256), [Crypt::Digest::SHA3\_384](https://metacpan.org/pod/Crypt::Digest::SHA3_384), [Crypt::Digest::SHA3\_512](https://metacpan.org/pod/Crypt::Digest::SHA3_512), [Crypt::Digest::SHAKE](https://metacpan.org/pod/Crypt::Digest::SHAKE)
37
38 - Message Authentication Codes
39
40 [Crypt::Mac::F9](https://metacpan.org/pod/Crypt::Mac::F9), [Crypt::Mac::HMAC](https://metacpan.org/pod/Crypt::Mac::HMAC), [Crypt::Mac::OMAC](https://metacpan.org/pod/Crypt::Mac::OMAC), [Crypt::Mac::Pelican](https://metacpan.org/pod/Crypt::Mac::Pelican), [Crypt::Mac::PMAC](https://metacpan.org/pod/Crypt::Mac::PMAC), [Crypt::Mac::XCBC](https://metacpan.org/pod/Crypt::Mac::XCBC), [Crypt::Mac::Poly1305](https://metacpan.org/pod/Crypt::Mac::Poly1305)
41
42 - Public key cryptography
43
44 [Crypt::PK::RSA](https://metacpan.org/pod/Crypt::PK::RSA), [Crypt::PK::DSA](https://metacpan.org/pod/Crypt::PK::DSA), [Crypt::PK::ECC](https://metacpan.org/pod/Crypt::PK::ECC), [Crypt::PK::DH](https://metacpan.org/pod/Crypt::PK::DH)
45
46 - Cryptographically secure random number generators
47
48 [Crypt::PRNG](https://metacpan.org/pod/Crypt::PRNG), [Crypt::PRNG::Fortuna](https://metacpan.org/pod/Crypt::PRNG::Fortuna), [Crypt::PRNG::Yarrow](https://metacpan.org/pod/Crypt::PRNG::Yarrow), [Crypt::PRNG::RC4](https://metacpan.org/pod/Crypt::PRNG::RC4), [Crypt::PRNG::Sober128](https://metacpan.org/pod/Crypt::PRNG::Sober128), [Crypt::PRNG::ChaCha20](https://metacpan.org/pod/Crypt::PRNG::ChaCha20)
49
50 - Key derivation functions - PBKDF1, PBKFD2 and HKDF
51
52 [Crypt::KeyDerivation](https://metacpan.org/pod/Crypt::KeyDerivation)
53
54 - Other handy functions related to cryptography
55
56 [Crypt::Misc](https://metacpan.org/pod/Crypt::Misc)
57
58 # LICENSE
59
60 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
61
62 # COPYRIGHT
63
64 Copyright (c) 2013+ DCIT, a.s. [http://www.dcit.cz](http://www.dcit.cz) / Karel Miko
4242 OUTPUT:
4343 RETVAL
4444
45 int
45 void
4646 set_iv(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce)
47 CODE:
47 PPCODE:
4848 {
4949 int rv;
5050 STRLEN iv_len=0;
5454 iv = (unsigned char *) SvPVbyte(nonce, iv_len);
5555 rv = chacha20poly1305_setiv(&self->state, iv, (unsigned long)iv_len);
5656 if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv));
57 RETVAL = rv;
57 XPUSHs(ST(0)); /* return self */;
5858 }
59 OUTPUT:
60 RETVAL
6159
62 int
60 void
6361 set_iv_rfc7905(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce, UV seqnum)
64 CODE:
62 PPCODE:
6563 {
6664 int rv;
6765 STRLEN iv_len=0;
7169 iv = (unsigned char *) SvPVbyte(nonce, iv_len);
7270 rv = chacha20poly1305_setiv_rfc7905(&self->state, iv, (unsigned long)iv_len, (ulong64)seqnum);
7371 if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv_rfc7905 failed: %s", error_to_string(rv));
74 RETVAL = rv;
72 XPUSHs(ST(0)); /* return self */
7573 }
76 OUTPUT:
77 RETVAL
7874
79 int
75 void
8076 adata_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
81 CODE:
77 PPCODE:
8278 {
8379 int rv;
8480 STRLEN in_data_len;
8783 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
8884 rv = chacha20poly1305_add_aad(&self->state, in_data, (unsigned long)in_data_len);
8985 if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_add_aad failed: %s", error_to_string(rv));
90 RETVAL = rv;
86 XPUSHs(ST(0)); /* return self */
9187 }
92 OUTPUT:
93 RETVAL
9488
9589 SV *
9690 decrypt_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
138138 }
139139 }
140140
141 int
142 aad_add(Crypt::AuthEnc::EAX self, SV * adata)
143 CODE:
141 void
142 adata_add(Crypt::AuthEnc::EAX self, SV * adata)
143 PPCODE:
144144 {
145145 STRLEN h_len;
146 int rv;
146147 unsigned char *h;
147148 h = (unsigned char *)SvPVbyte(adata, h_len);
148 RETVAL = eax_addheader(&self->state, h, (unsigned long)h_len);
149 rv = eax_addheader(&self->state, h, (unsigned long)h_len);
150 if (rv != CRYPT_OK) croak("FATAL: eax_addheader failed: %s", error_to_string(rv));
151 XPUSHs(ST(0)); /* return self */
149152 }
150 OUTPUT:
151 RETVAL
4545 OUTPUT:
4646 RETVAL
4747
48 int
48 void
4949 reset(Crypt::AuthEnc::GCM self)
50 CODE:
50 PPCODE:
5151 {
5252 int rv;
5353 rv = gcm_reset(&self->state);
5454 if (rv != CRYPT_OK) croak("FATAL: gcm_reset failed: %s", error_to_string(rv));
55 RETVAL = rv;
55 XPUSHs(ST(0)); /* return self */
5656 }
57 OUTPUT:
58 RETVAL
5957
6058 SV *
6159 encrypt_add(Crypt::AuthEnc::GCM self, SV * data)
8280 OUTPUT:
8381 RETVAL
8482
85 int
83 void
8684 iv_add(Crypt::AuthEnc::GCM self, SV * data)
87 CODE:
85 PPCODE:
8886 {
8987 int rv;
9088 STRLEN in_data_len;
9391 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
9492 rv = gcm_add_iv(&self->state, in_data, (unsigned long)in_data_len);
9593 if (rv != CRYPT_OK) croak("FATAL: gcm_add_iv failed: %s", error_to_string(rv));
96 RETVAL = rv;
94 XPUSHs(ST(0)); /* return self */
9795 }
98 OUTPUT:
99 RETVAL
10096
101 int
97 void
10298 adata_add(Crypt::AuthEnc::GCM self, SV * data)
103 CODE:
99 PPCODE:
104100 {
105101 int rv;
106102 STRLEN in_data_len;
109105 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
110106 rv = gcm_add_aad(&self->state, in_data, (unsigned long)in_data_len);
111107 if (rv != CRYPT_OK) croak("FATAL: gcm_add_aad failed: %s", error_to_string(rv));
112 RETVAL = rv;
108 XPUSHs(ST(0)); /* return self */
113109 }
114 OUTPUT:
115 RETVAL
116110
117111 SV *
118112 decrypt_add(Crypt::AuthEnc::GCM self, SV * data)
00 MODULE = CryptX PACKAGE = Crypt::AuthEnc::OCB
11
22 Crypt::AuthEnc::OCB
3 _new(char * cipher_name, SV * key, SV * nonce)
3 _new(char * cipher_name, SV * key, SV * nonce, unsigned long taglen)
44 CODE:
55 {
66 STRLEN k_len=0;
2020 Newz(0, RETVAL, 1, struct ocb_struct);
2121 if (!RETVAL) croak("FATAL: Newz failed");
2222
23 if (ocb3_init(&RETVAL->state, id, k, (unsigned long)k_len, n, (unsigned long)n_len) != CRYPT_OK) {
23 if (ocb3_init(&RETVAL->state, id, k, (unsigned long)k_len, n, (unsigned long)n_len, taglen) != CRYPT_OK) {
2424 croak("FATAL: ocb setup failed");
2525 }
2626 }
4242 RETVAL
4343
4444 void
45 aad_add(Crypt::AuthEnc::OCB self, SV * data)
46 CODE:
45 adata_add(Crypt::AuthEnc::OCB self, SV * data)
46 PPCODE:
4747 {
4848 int rv;
4949 STRLEN in_data_len;
5555 rv = ocb3_add_aad(&self->state, in_data, (unsigned long)in_data_len);
5656 if (rv != CRYPT_OK) croak("FATAL: ocb3_add_aad failed: %s", error_to_string(rv));
5757 }
58 XPUSHs(ST(0)); /* return self */
5859 }
5960
6061 SV *
1515
1616 void
1717 reset(Crypt::Checksum::Adler32 self)
18 CODE:
18 PPCODE:
19 {
1920 adler32_init(self);
21 XPUSHs(ST(0)); /* return self */
22 }
2023
2124 Crypt::Checksum::Adler32
2225 clone(Crypt::Checksum::Adler32 self)
1515
1616 void
1717 reset(Crypt::Checksum::CRC32 self)
18 CODE:
18 PPCODE:
19 {
1920 crc32_init(self);
21 XPUSHs(ST(0)); /* return self */
22 }
2023
2124 Crypt::Checksum::CRC32
2225 clone(Crypt::Checksum::CRC32 self)
3030 void
3131 reset(self)
3232 Crypt::Digest self
33 CODE:
33 PPCODE:
3434 {
3535 int rv;
3636 rv = self->desc->init(&self->state);
3737 if (rv != CRYPT_OK) croak("FATAL: digest init failed: %s", error_to_string(rv));
38 XPUSHs(ST(0)); /* return self */
3839 }
3940
4041 Crypt::Digest
2222
2323 void
2424 reset(Crypt::Digest::SHAKE self)
25 CODE:
25 PPCODE:
2626 {
2727 int rv;
2828 rv = sha3_shake_init(&self->state, self->num);
2929 if (rv != CRYPT_OK) croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv));
30 XPUSHs(ST(0)); /* return self */
3031 }
3132
3233 Crypt::Digest::SHAKE
1616 RETVAL
1717
1818 void
19 _generate_key(Crypt::PK::DH self, int key_size=256)
20 PPCODE:
21 {
22 int rv;
19 _generate_key_size(Crypt::PK::DH self, int groupsize=256)
20 PPCODE:
21 {
22 int rv;
23 rv = dh_set_pg_groupsize(groupsize, &self->key);
24 if (rv != CRYPT_OK) croak("FATAL: dh_set_pg_groupsize failed: %s", error_to_string(rv));
25 rv = dh_generate_key(&self->pstate, self->pindex, &self->key);
26 if (rv != CRYPT_OK) croak("FATAL: dh_generate_key failed: %s", error_to_string(rv));
27 XPUSHs(ST(0)); /* return self */
28 }
29
30 void
31 _generate_key_gp(Crypt::PK::DH self, char *g, char *p)
32 PPCODE:
33 {
34 int rv;
35 unsigned char pbin[1024], gbin[512];
36 unsigned long plen=sizeof(pbin), glen=sizeof(gbin);
37
38 if (p && strlen(p) > 0 && g && strlen(g) > 0) {
39 rv = radix_to_bin(p, 16, pbin, &plen);
40 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(p) failed: %s", error_to_string(rv));
41 rv = radix_to_bin(g, 16, gbin, &glen);
42 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(g) failed: %s", error_to_string(rv));
43
44 rv = dh_set_pg(pbin, plen, gbin, glen, &self->key);
45 if (rv != CRYPT_OK) croak("FATAL: dh_set_pg failed: %s", error_to_string(rv));
46 rv = dh_generate_key(&self->pstate, self->pindex, &self->key);
47 if (rv != CRYPT_OK) croak("FATAL: dh_generate_key failed: %s", error_to_string(rv));
48 }
49
50 XPUSHs(ST(0)); /* return self */
51 }
52
53 void
54 _generate_key_dhparam(Crypt::PK::DH self, SV * dhparam)
55 PPCODE:
56 {
57 int rv;
58 unsigned char *data=NULL;
59 STRLEN data_len=0;
60 data = (unsigned char *)SvPVbyte(dhparam, data_len);
61 /* load d p q */
62 rv = dh_set_pg_dhparam(data, data_len, &self->key);
63 if (rv != CRYPT_OK) croak("FATAL: dh_set_pg_dhparam failed: %s", error_to_string(rv));
2364 /* gen the key */
24 rv = dh_make_key(&self->pstate, self->pindex, key_size, &self->key);
25 if (rv != CRYPT_OK) croak("FATAL: dh_make_key failed: %s", error_to_string(rv));
26 XPUSHs(ST(0)); /* return self */
27 }
28
29 void
30 _generate_key_ex(Crypt::PK::DH self, SV * g, SV * p)
31 PPCODE:
32 {
33 int rv;
34 STRLEN p_len = 0;
35 STRLEN g_len = 0;
36 unsigned char *p_ptr=NULL;
37 unsigned char *g_ptr=NULL;
38
39 p_ptr = (unsigned char *)SvPVbyte(p, p_len);
40 g_ptr = (unsigned char *)SvPVbyte(g, g_len);
41
42 /* gen the key */
43 rv = dh_make_key_ex(&self->pstate, self->pindex, (const char *) g_ptr, (const char *) p_ptr, &self->key);
44 if (rv != CRYPT_OK) croak("FATAL: dh_make_key_ex failed: %s", error_to_string(rv));
65 rv = dh_generate_key(&self->pstate, self->pindex, &self->key);
66 if (rv != CRYPT_OK) croak("FATAL: dh_generate_key failed: %s", error_to_string(rv));
4567 XPUSHs(ST(0)); /* return self */
4668 }
4769
6789 int rv;
6890 unsigned char *data=NULL;
6991 STRLEN data_len=0;
92 unsigned char pbin[1024], gbin[512];
93 unsigned long plen=sizeof(pbin), glen=sizeof(gbin);
7094
7195 data = (unsigned char *)SvPVbyte(raw_key, data_len);
7296 if (self->key.type != -1) { dh_free(&self->key); self->key.type = -1; }
73 /* public */
74 if (type == 0) {
75 rv = dh_import_raw(data, (unsigned long)data_len, PK_PUBLIC, g, p, &self->key);
76 if (rv != CRYPT_OK) croak("FATAL: dh_import_raw failed: %s", error_to_string(rv));
77 }
78 /* private */
79 else if (type == 1) {
80 rv = dh_import_raw(data, (unsigned long)data_len, PK_PRIVATE, g, p, &self->key);
81 if (rv != CRYPT_OK) croak("FATAL: dh_import_raw failed: %s", error_to_string(rv));
82 }
83 else {
84 croak("FATAL: import_raw invalid type '%d'", type);
97
98 if (p && strlen(p) > 0 && g && strlen(g) > 0) {
99 rv = radix_to_bin(p, 16, pbin, &plen);
100 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(p) failed: %s", error_to_string(rv));
101 rv = radix_to_bin(g, 16, gbin, &glen);
102 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(g) failed: %s", error_to_string(rv));
103
104 rv = dh_set_pg(pbin, plen, gbin, glen, &self->key);
105 if (rv != CRYPT_OK) croak("FATAL: dh_set_pg failed: %s", error_to_string(rv));
106
107 if (type == 0) {
108 /* public */
109 rv = dh_set_key(data, (unsigned long)data_len, PK_PUBLIC, &self->key);
110 if (rv != CRYPT_OK) croak("FATAL: dh_set_key failed: %s", error_to_string(rv));
111 }
112 else if (type == 1) {
113 /* private */
114 rv = dh_set_key(data, (unsigned long)data_len, PK_PRIVATE, &self->key);
115 if (rv != CRYPT_OK) croak("FATAL: dh_set_key failed: %s", error_to_string(rv));
116 }
117 else {
118 croak("FATAL: import_raw invalid type '%d'", type);
119 }
85120 }
86121
87122 XPUSHs(ST(0)); /* return self */
99134 size(Crypt::PK::DH self)
100135 CODE:
101136 if (self->key.type == -1) XSRETURN_UNDEF;
102 RETVAL = dh_get_size(&self->key);
137 RETVAL = dh_get_groupsize(&self->key);
103138 OUTPUT:
104139 RETVAL
105140
163198 not_used = hv_store(rv_hash, "g", 1, newSVpv("", 0), 0);
164199 }
165200 /* =====> size */
166 not_used = hv_store(rv_hash, "size", 4, newSViv(dh_get_size(&self->key)), 0);
201 not_used = hv_store(rv_hash, "size", 4, newSViv(dh_get_groupsize(&self->key)), 0);
167202 /* =====> type */
168203 not_used = hv_store(rv_hash, "type", 4, newSViv(self->key.type), 0);
169204 if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
238273 RETVAL
239274
240275 SV *
241 _encrypt(Crypt::PK::DH self, SV * data, char * hash_name)
242 CODE:
243 {
244 int rv, hash_id;
245 unsigned char *data_ptr=NULL;
246 STRLEN data_len=0;
247 unsigned long buffer_len = 1024;
248 unsigned char buffer[1024];
249
250 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
251
252 hash_id = find_hash(hash_name);
253 if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
254 rv = dh_encrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
255 &self->pstate, self->pindex,
256 hash_id, &self->key);
257 if (rv != CRYPT_OK) croak("FATAL: dh_encrypt_key failed: %s", error_to_string(rv));
258 RETVAL = newSVpvn((char*)buffer, buffer_len);
259 }
260 OUTPUT:
261 RETVAL
262
263 SV *
264 _decrypt(Crypt::PK::DH self, SV * data)
265 CODE:
266 {
267 int rv;
268 unsigned char *data_ptr=NULL;
269 STRLEN data_len=0;
270 unsigned long buffer_len = 1024;
271 unsigned char buffer[1024];
272
273 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
274
275 rv = dh_decrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len, &self->key);
276 if (rv != CRYPT_OK) croak("FATAL: dh_decrypt_key failed: %s", error_to_string(rv));
277 RETVAL = newSVpvn((char*)buffer, buffer_len);
278 }
279 OUTPUT:
280 RETVAL
281
282 SV *
283 _sign(Crypt::PK::DH self, SV * data)
284 CODE:
285 {
286 int rv;
287 unsigned char *data_ptr=NULL;
288 STRLEN data_len=0;
289 unsigned long buffer_len = 1024;
290 unsigned char buffer[1024];
291
292 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
293
294 rv = dh_sign_hash(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
295 &self->pstate, self->pindex,
296 &self->key);
297 if (rv != CRYPT_OK) croak("FATAL: dh_sign_hash failed: %s", error_to_string(rv));
298 RETVAL = newSVpvn((char*)buffer, buffer_len);
299 }
300 OUTPUT:
301 RETVAL
302
303 int
304 _verify(Crypt::PK::DH self, SV * sig, SV * data)
305 CODE:
306 {
307 int rv, stat;
308 unsigned char *data_ptr=NULL;
309 STRLEN data_len=0;
310 unsigned char *sig_ptr=NULL;
311 STRLEN sig_len=0;
312
313 data_ptr = (unsigned char *)SvPVbyte(data, data_len);
314 sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
315
316 RETVAL = 1;
317 rv = dh_verify_hash(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
318 if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
319 }
320 OUTPUT:
321 RETVAL
322
323 SV *
324276 shared_secret(Crypt::PK::DH self, Crypt::PK::DH pubkey)
325277 CODE:
326278 {
340292 CODE:
341293 {
342294 int rv;
343 unsigned long len, buffer_len = 1024;
344 unsigned char buffer[1024];
345 void *key;
295 unsigned char out[1024];
296 unsigned long out_len = 1024;
346297
347298 RETVAL = newSVpvn(NULL, 0); /* undef */
348299 if (strnEQ(type, "private", 7)) {
349 key = self->key.x;
300 rv = dh_export_key(out, &out_len, PK_PRIVATE, &self->key);
301 if (rv != CRYPT_OK) croak("FATAL: dh_export_key(PK_PRIVATE) failed: %s", error_to_string(rv));
302 RETVAL = newSVpvn((char*)out, out_len);
350303 }
351304 else if (strnEQ(type, "public", 6)) {
352 key = self->key.y;
305 rv = dh_export_key(out, &out_len, PK_PUBLIC, &self->key);
306 if (rv != CRYPT_OK) croak("FATAL: dh_export_key(PK_PUBLIC) failed: %s", error_to_string(rv));
307 RETVAL = newSVpvn((char*)out, out_len);
353308 }
354309 else {
355310 croak("FATAL: export_key_raw: invalid type '%s'", type);
356311 }
357
358 len = (unsigned long)mp_unsigned_bin_size(key);
359 if (buffer_len < len) {
360 croak("FATAL: %s", error_to_string(CRYPT_BUFFER_OVERFLOW));
361 }
362 rv = mp_to_unsigned_bin(key, buffer);
363 if (rv != CRYPT_OK) croak("FATAL: %s", error_to_string(rv));
364 RETVAL = newSVpvn((char*)buffer, len);
365 }
366 OUTPUT:
367 RETVAL
368
369 int
370 _is_pubkey_valid(Crypt::PK::DH self);
371 CODE:
372 {
373 int rv, i, bits_set = 0;
374 mp_int one, two, p1, *y;
375 mp_digit digit;
376
377 if ((rv = mp_init_multi(&one, &two, &p1, NULL)) != MP_OKAY) {
378 croak("FATAL: %s", error_to_string(rv));
379 }
380
381 y = self->key.y;
382 mp_set(&one, 1);
383 mp_set(&two, 2);
384
385 /* p1 = p-1 */
386 if ((rv = mp_sub(self->key.prime, &one, &p1)) != MP_OKAY) {
387 croak("FATAL: %s", error_to_string(rv));
388 }
389 /* valid public key cannot be negative */
390 if (y->sign == MP_NEG) {
391 RETVAL = 0;
392 }
393 /* valid public key != 1 */
394 else if (mp_cmp(y, &one) == MP_EQ) {
395 RETVAL = 0;
396 }
397 /* public key cannot be > p-1 */
398 else if (mp_cmp(y, &p1) == MP_GT) {
399 RETVAL = 0;
400 }
401 /* if base == 2, public must have more than one bit set */
402 else if (mp_cmp(self->key.base, &two) == MP_EQ) {
403 for (i = 0; i < y->used; i++) {
404 digit = y->dp[i];
405 while (digit > ((mp_digit) 0)) {
406 if (digit & ((mp_digit) 1))
407 bits_set++;
408 digit >>= ((mp_digit) 1);
409 }
410 }
411 if (bits_set > 1)
412 RETVAL = 1;
413 else RETVAL = 0;
414 }
415 else RETVAL = 1;
416312 }
417313 OUTPUT:
418314 RETVAL
422318 CODE:
423319 if (self->key.type != -1) { dh_free(&self->key); self->key.type = -1; }
424320 Safefree(self);
425
1616 RETVAL
1717
1818 void
19 generate_key(Crypt::PK::DSA self, int group_size=30, int modulus_size=256)
19 _generate_key_size(Crypt::PK::DSA self, int group_size=30, int modulus_size=256)
2020 PPCODE:
2121 {
2222 int rv;
2323 /* gen the key */
2424 rv = dsa_make_key(&self->pstate, self->pindex, group_size, modulus_size, &self->key);
2525 if (rv != CRYPT_OK) croak("FATAL: dsa_make_key failed: %s", error_to_string(rv));
26 XPUSHs(ST(0)); /* return self */
27 }
28
29 void
30 _generate_key_dsaparam(Crypt::PK::DSA self, SV * dsaparam)
31 PPCODE:
32 {
33 int rv;
34 unsigned char *data=NULL;
35 STRLEN data_len=0;
36 data = (unsigned char *)SvPVbyte(dsaparam, data_len);
37 /* load d p q */
38 rv = dsa_set_pqg_dsaparam(data, data_len, &self->key);
39 if (rv != CRYPT_OK) croak("FATAL: dsa_set_pqg_dsaparam failed: %s", error_to_string(rv));
40 /* gen the key */
41 rv = dsa_generate_key(&self->pstate, self->pindex, &self->key);
42 if (rv != CRYPT_OK) croak("FATAL: dsa_generate_key failed: %s", error_to_string(rv));
43 XPUSHs(ST(0)); /* return self */
44 }
45
46 void
47 _generate_key_pqg_hex(Crypt::PK::DSA self, char *p, char *q, char *g)
48 PPCODE:
49 {
50 int rv;
51 unsigned char pbin[512], qbin[512], gbin[512];
52 unsigned long plen=sizeof(pbin), qlen=sizeof(qbin), glen=sizeof(gbin);
53 if (!p || !strlen(p) || !q || !strlen(q) || !g || !strlen(g)) {
54 croak("FATAL: generate_key_pqg_hex incomplete args");
55 }
56 /* set p q g */
57 rv = radix_to_bin(p, 16, pbin, &plen);
58 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(p) failed: %s", error_to_string(rv));
59 rv = radix_to_bin(q, 16, qbin, &qlen);
60 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(q) failed: %s", error_to_string(rv));
61 rv = radix_to_bin(g, 16, gbin, &glen);
62 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(g) failed: %s", error_to_string(rv));
63 rv = dsa_set_pqg(pbin, plen, qbin, qlen, gbin, glen, &self->key);
64 if (rv != CRYPT_OK) croak("FATAL: dsa_set_pqg failed: %s", error_to_string(rv));
65 /* gen the key */
66 rv = dsa_generate_key(&self->pstate, self->pindex, &self->key);
67 if (rv != CRYPT_OK) croak("FATAL: dsa_generate_key failed: %s", error_to_string(rv));
2668 XPUSHs(ST(0)); /* return self */
2769 }
2870
4688 PPCODE:
4789 {
4890 int rv;
91 unsigned char pbin[512], qbin[512], gbin[512], xbin[512], ybin[512];
92 unsigned long plen=sizeof(pbin), qlen=sizeof(qbin), glen=sizeof(gbin), xlen=sizeof(xbin), ylen=sizeof(ybin);
93
4994 if (self->key.type != -1) { dsa_free(&self->key); self->key.type = -1; }
50 rv = dsa_import_radix(16, p, q, g, x, y, &self->key);
51 if (rv != CRYPT_OK) croak("FATAL: dsa_import_radix failed: %s", error_to_string(rv));
95
96 if (p && strlen(p) > 0 && q && strlen(q) > 0 && g && strlen(g) > 0 && y && strlen(y) > 0) {
97 rv = radix_to_bin(p, 16, pbin, &plen);
98 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(p) failed: %s", error_to_string(rv));
99 rv = radix_to_bin(q, 16, qbin, &qlen);
100 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(q) failed: %s", error_to_string(rv));
101 rv = radix_to_bin(g, 16, gbin, &glen);
102 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(g) failed: %s", error_to_string(rv));
103 rv = dsa_set_pqg(pbin, plen, qbin, qlen, gbin, glen, &self->key);
104 if (rv != CRYPT_OK) croak("FATAL: dsa_set_pqg failed: %s", error_to_string(rv));
105
106 rv = radix_to_bin(y, 16, ybin, &ylen);
107 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(y) failed: %s", error_to_string(rv));
108 if (x && strlen(x) > 0) {
109 /* private */
110 rv = radix_to_bin(x, 16, xbin, &xlen);
111 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(x) failed: %s", error_to_string(rv));
112 rv = dsa_set_key(xbin, xlen, PK_PRIVATE, &self->key);
113 if (rv != CRYPT_OK) croak("FATAL: dsa_set_key failed: %s", error_to_string(rv));
114 }
115 else {
116 /* public */
117 rv = dsa_set_key(ybin, ylen, PK_PUBLIC, &self->key);
118 if (rv != CRYPT_OK) croak("FATAL: dsa_set_key failed: %s", error_to_string(rv));
119 }
120 }
121
52122 XPUSHs(ST(0)); /* return self */
53123 }
54124
260330 sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
261331
262332 RETVAL = 1;
333 stat = 0;
263334 rv = dsa_verify_hash(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
264335 if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
265336 }
4545 }
4646
4747 void
48 _import_pkcs8(Crypt::PK::ECC self, SV * key_data)
48 _import_pkcs8(Crypt::PK::ECC self, SV * key_data, SV * passwd)
49 PPCODE:
50 {
51 int rv;
52 unsigned char *data=NULL, *pwd=NULL;
53 STRLEN data_len=0, pwd_len=0;
54
55 data = (unsigned char *)SvPVbyte(key_data, data_len);
56 if (SvOK(passwd)) {
57 pwd = (unsigned char *)SvPVbyte(passwd, pwd_len);
58 }
59 _ecc_free_key(&self->key, &self->dp);
60 rv = ecc_import_pkcs8(data, (unsigned long)data_len, pwd, pwd_len, &self->key, &self->dp);
61 if (rv != CRYPT_OK) croak("FATAL: ecc_import_pkcs8 failed: %s", error_to_string(rv));
62 XPUSHs(ST(0)); /* return self */
63 }
64
65 void
66 import_key_raw(Crypt::PK::ECC self, SV * key_data, SV * curve)
4967 PPCODE:
5068 {
5169 int rv;
5472
5573 data = (unsigned char *)SvPVbyte(key_data, data_len);
5674 _ecc_free_key(&self->key, &self->dp);
57 rv = ecc_import_pkcs8(data, (unsigned long)data_len, NULL, 0, &self->key, &self->dp);
58 if (rv != CRYPT_OK) croak("FATAL: ecc_import_pkcs8 failed: %s", error_to_string(rv));
59 XPUSHs(ST(0)); /* return self */
60 }
61
62 void
63 import_key_raw(Crypt::PK::ECC self, SV * key_data, SV * curve)
64 PPCODE:
65 {
66 int rv;
67 unsigned char *data=NULL;
68 STRLEN data_len=0;
69
70 data = (unsigned char *)SvPVbyte(key_data, data_len);
71 _ecc_free_key(&self->key, &self->dp);
72
75
7376 _ecc_set_dp_from_SV(&self->dp, curve); /* croaks on error */
74
77
7578 rv = ecc_import_raw(data, (unsigned long)data_len, &self->key, &self->dp);
7679 if (rv != CRYPT_OK) croak("FATAL: ecc_import_raw failed: %s", error_to_string(rv));
7780 XPUSHs(ST(0)); /* return self */
251254 RETVAL = newSVpvn((char*)out, out_len);
252255 }
253256 else if (strnEQ(type, "public_compressed", 17)) {
254 rv = ecc_export_raw(out, &out_len, PK_PUBLIC_COMPRESSED, &self->key);
257 rv = ecc_export_raw(out, &out_len, PK_PUBLIC|PK_COMPRESSED, &self->key);
255258 if (rv != CRYPT_OK) croak("FATAL: ecc_export_raw(public_compressed) failed: %s", error_to_string(rv));
256259 RETVAL = newSVpvn((char*)out, out_len);
257260 }
355358 sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
356359
357360 RETVAL = 1;
361 stat = 0;
358362 if (ix == 1) {
359363 rv = ecc_verify_hash_rfc7518(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
360364 }
4343 }
4444
4545 void
46 _import_pkcs8(Crypt::PK::RSA self, SV * key_data)
46 _import_pkcs8(Crypt::PK::RSA self, SV * key_data, SV * passwd)
47 PPCODE:
48 {
49 int rv;
50 unsigned char *data=NULL, *pwd=NULL;
51 STRLEN data_len=0, pwd_len=0;
52
53 data = (unsigned char *)SvPVbyte(key_data, data_len);
54 if (SvOK(passwd)) {
55 pwd = (unsigned char *)SvPVbyte(passwd, pwd_len);
56 }
57 if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
58 rv = rsa_import_pkcs8(data, (unsigned long)data_len, pwd, pwd_len, &self->key);
59 if (rv != CRYPT_OK) croak("FATAL: rsa_import_pkcs8 failed: %s", error_to_string(rv));
60 XPUSHs(ST(0)); /* return self */
61 }
62
63 void
64 _import_x509(Crypt::PK::RSA self, SV * key_data)
4765 PPCODE:
4866 {
4967 int rv;
5270
5371 data = (unsigned char *)SvPVbyte(key_data, data_len);
5472 if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
55 rv = rsa_import_pkcs8(data, (unsigned long)data_len, NULL, 0, &self->key);
56 if (rv != CRYPT_OK) croak("FATAL: rsa_import_pkcs8 failed: %s", error_to_string(rv));
73 rv = rsa_import_x509(data, (unsigned long)data_len, &self->key);
74 if (rv != CRYPT_OK) croak("FATAL: rsa_import_x509 failed: %s", error_to_string(rv));
5775 XPUSHs(ST(0)); /* return self */
5876 }
5977
6280 PPCODE:
6381 {
6482 int rv;
65 if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
66 rv = rsa_import_radix(16, N, e, d, p, q, dP, dQ, qP, &self->key);
67 if (rv != CRYPT_OK) croak("FATAL: rsa_import_radix failed: %s", error_to_string(rv));
83 unsigned char Nbin[1024], ebin[128], dbin[1024], pbin[512], qbin[512], dPbin[512], dQbin[512], qPbin[512];
84 unsigned long Nlen=sizeof(Nbin), elen=sizeof(ebin), dlen=sizeof(dbin), plen=sizeof(pbin),
85 qlen=sizeof(qbin), dPlen=sizeof(dPbin), dQlen=sizeof(dQbin), qPlen=sizeof(qPbin);
86
87 rv = radix_to_bin(N, 16, Nbin, &Nlen);
88 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(N) failed: %s", error_to_string(rv));
89 rv = radix_to_bin(e, 16, ebin, &elen);
90 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(e) failed: %s", error_to_string(rv));
91
92 if (d && strlen(d) > 0) {
93 /* private */
94 rv = radix_to_bin(d, 16, dbin, &dlen);
95 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(d) failed: %s", error_to_string(rv));
96 rv = rsa_set_key(Nbin, Nlen, ebin, elen, dbin, dlen, &self->key);
97 if (rv != CRYPT_OK) croak("FATAL: rsa_set_key failed: %s", error_to_string(rv));
98 }
99 else {
100 /* public */
101 rv = rsa_set_key(Nbin, Nlen, ebin, elen, NULL, 0, &self->key);
102 if (rv != CRYPT_OK) croak("FATAL: rsa_set_key failed: %s", error_to_string(rv));
103 }
104
105 if (p && strlen(p) > 0 && q && strlen(q) > 0) {
106 /* private only */
107 rv = radix_to_bin(p, 16, pbin, &plen);
108 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(p) failed: %s", error_to_string(rv));
109 rv = radix_to_bin(q, 16, qbin, &qlen);
110 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(q) failed: %s", error_to_string(rv));
111 rv = rsa_set_factors(pbin, plen, qbin, qlen, &self->key);
112 if (rv != CRYPT_OK) croak("FATAL: rsa_set_factors failed: %s", error_to_string(rv));
113 }
114
115 if (dP && strlen(dP) > 0 && dQ && strlen(dQ) > 0 && qP && strlen(qP) > 0) {
116 /* private only */
117 rv = radix_to_bin(dP, 16, dPbin, &dPlen);
118 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(dP) failed: %s", error_to_string(rv));
119 rv = radix_to_bin(dQ, 16, dQbin, &dQlen);
120 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(dQ) failed: %s", error_to_string(rv));
121 rv = radix_to_bin(qP, 16, qPbin, &qPlen);
122 if (rv != CRYPT_OK) croak("FATAL: radix_to_bin(qP) failed: %s", error_to_string(rv));
123 rv = rsa_set_crt_params(dPbin, dPlen, dQbin, dQlen, qPbin, qPlen, &self->key);
124 if (rv != CRYPT_OK) croak("FATAL: rsa_set_crt_params failed: %s", error_to_string(rv));
125 }
126
68127 XPUSHs(ST(0)); /* return self */
69128 }
70129
206265 {
207266 int rv;
208267 unsigned char out[4096];
209 unsigned long int out_len = 4096;
268 unsigned long out_len = 4096;
210269
211270 RETVAL = newSVpvn(NULL, 0); /* undef */
212271 if (strnEQ(type, "private", 7)) {
376435 sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
377436
378437 RETVAL = 1;
438 stat = 0;
379439 if (strnEQ(padding, "pss", 3)) {
380440 hash_id = find_hash(hash_name);
381441 if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
415475 CODE:
416476 if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
417477 Safefree(self);
418
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use base qw(Crypt::AuthEnc Exporter);
77 our %EXPORT_TAGS = ( all => [qw( ccm_encrypt_authenticate ccm_decrypt_verify )] );
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use base qw(Crypt::AuthEnc Exporter);
77 our %EXPORT_TAGS = ( all => [qw( chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify )] );
4444
4545 =head1 NAME
4646
47 Crypt::AuthEnc::ChaCha20Poly1305 - Authenticated encryption in ChaCha20Poly1305 mode
47 Crypt::AuthEnc::ChaCha20Poly1305 - Authenticated encryption in ChaCha20-Poly1305 mode
4848
4949 =head1 SYNOPSIS
5050
5353
5454 # encrypt and authenticate
5555 my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
56 $ae->aad_add('additional_authenticated_data1');
57 $ae->aad_add('additional_authenticated_data2');
56 $ae->adata_add('additional_authenticated_data1');
57 $ae->adata_add('additional_authenticated_data2');
5858 $ct = $ae->encrypt_add('data1');
5959 $ct = $ae->encrypt_add('data2');
6060 $ct = $ae->encrypt_add('data3');
6262
6363 # decrypt and verify
6464 my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
65 $ae->aad_add('additional_authenticated_data1');
66 $ae->aad_add('additional_authenticated_data2');
65 $ae->adata_add('additional_authenticated_data1');
66 $ae->adata_add('additional_authenticated_data2');
6767 $pt = $ae->decrypt_add('ciphertext1');
6868 $pt = $ae->decrypt_add('ciphertext2');
6969 $pt = $ae->decrypt_add('ciphertext3');
116116 # $key ..... encryption key of proper length (128 or 256 bits / 16 or 32 bytes)
117117 # $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
118118
119 =head2 aad_add
119 =head2 adata_add
120120
121 Add B<additional authenticated data>.
121122 Can be called before the first C<encrypt_add> or C<decrypt_add>;
122123
123 $ae->aad_add($aad_data); #can be called multiple times
124 $ae->adata_add($aad_data); #can be called multiple times
124125
125126 =head2 encrypt_add
126127
140141 #or
141142 my $tag = $ae->decrypt_done; # returns $tag value
142143
144 =head2 set_iv
145
146 my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key)->set_iv($iv);
147 # $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
148
149 =head2 set_iv_rfc7905
150
151 See L<https://tools.ietf.org/html/rfc7905>
152
153 my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key)->set_iv_rfc7905($iv, $seqnum);
154 # $iv ...... initialization vector (96 bits / 12 bytes)
155 # $seqnum .. 64bit integer (sequence number)
156
143157 =head2 clone
144158
145159 my $ae_new = $ae->clone;
146
147 =head2 set_iv
148
149 $ae->set_iv($iv);
150
151 =head2 set_iv_rfc7905
152
153 $ae->set_iv_rfc7905($iv, $seqnum);
154160
155161 =head1 SEE ALSO
156162
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use base qw(Crypt::AuthEnc Exporter);
77 our %EXPORT_TAGS = ( all => [qw( eax_encrypt_authenticate eax_decrypt_verify )] );
1919 # - encrypt_done
2020 # - decrypt_add
2121 # - decrypt_done
22 # - aad_add
22 # - adata_add
2323
2424 sub new { my $class = shift; _new(Crypt::Cipher::_trans_cipher_name(shift), @_) }
2525
3131 my $plaintext = shift;
3232
3333 my $m = Crypt::AuthEnc::EAX->new($cipher_name, $key, $iv);
34 $m->aad_add($adata) if defined $adata;
34 $m->adata_add($adata) if defined $adata;
3535 my $ct = $m->encrypt_add($plaintext);
3636 my $tag = $m->encrypt_done;
3737 return ($ct, $tag);
4646 my $tag = shift;
4747
4848 my $m = Crypt::AuthEnc::EAX->new($cipher_name, $key, $iv);
49 $m->aad_add($adata) if defined $adata;
49 $m->adata_add($adata) if defined $adata;
5050 my $ct = $m->decrypt_add($ciphertext);
5151 return $m->decrypt_done($tag) ? $ct : undef;
5252 }
5353
54 sub header_add {
55 # obsolete, only for backwards compatibility
56 shift->aad_add(@_);
57 }
54 # obsolete, only for backwards compatibility
55 sub header_add { goto &adata_add }
56 sub aad_add { goto &adata_add }
5857
5958 1;
6059
7170
7271 # encrypt and authenticate
7372 my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
74 $ae->aad_add('additional_authenticated_data1');
75 $ae->aad_add('additional_authenticated_data2');
73 $ae->adata_add('additional_authenticated_data1');
74 $ae->adata_add('additional_authenticated_data2');
7675 $ct = $ae->encrypt_add('data1');
7776 $ct = $ae->encrypt_add('data2');
7877 $ct = $ae->encrypt_add('data3');
8079
8180 # decrypt and verify
8281 my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
83 $ae->aad_add('additional_authenticated_data1');
84 $ae->aad_add('additional_authenticated_data2');
82 $ae->adata_add('additional_authenticated_data1');
83 $ae->adata_add('additional_authenticated_data2');
8584 $pt = $ae->decrypt_add('ciphertext1');
8685 $pt = $ae->decrypt_add('ciphertext2');
8786 $pt = $ae->decrypt_add('ciphertext3');
141140 # $iv ...... unique initialization vector (no need to keep it secret)
142141 # $adata ... additional authenticated data (optional)
143142
144 =head2 aad_add
143 =head2 adata_add
145144
146 $ae->aad_add($adata); #can be called multiple times
145 $ae->adata_add($adata); #can be called multiple times
147146
148147 =head2 encrypt_add
149148
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use base qw(Crypt::AuthEnc Exporter);
77 our %EXPORT_TAGS = ( all => [qw( gcm_encrypt_authenticate gcm_decrypt_verify )] );
6464
6565 # encrypt and authenticate
6666 my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
67 $ae->aad_add('additional_authenticated_data1');
68 $ae->aad_add('additional_authenticated_data2');
67 $ae->adata_add('additional_authenticated_data1');
68 $ae->adata_add('additional_authenticated_data2');
6969 $ct = $ae->encrypt_add('data1');
7070 $ct = $ae->encrypt_add('data2');
7171 $ct = $ae->encrypt_add('data3');
7373
7474 # decrypt and verify
7575 my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
76 $ae->aad_add('additional_authenticated_data1');
77 $ae->aad_add('additional_authenticated_data2');
76 $ae->adata_add('additional_authenticated_data1');
77 $ae->adata_add('additional_authenticated_data2');
7878 $pt = $ae->decrypt_add('ciphertext1');
7979 $pt = $ae->decrypt_add('ciphertext2');
8080 $pt = $ae->decrypt_add('ciphertext3');
133133
134134 =head2 iv_add
135135
136 $ae->iv_add($iv_data); #can be called multiple times
136 Set initialization vector (IV).
137137
138 =head2 aad_add
138 $ae->iv_add($iv_data); #can be called multiple times
139139
140 Can be called B<after> all C<iv_add> calls but before the first C<encrypt_add> or C<decrypt_add>;
140 =head2 adata_add
141141
142 $ae->aad_add($aad_data); #can be called multiple times
142 Add B<additional authenticated data>.
143 Can be called B<after> all C<iv_add> calls but before the first C<encrypt_add> or C<decrypt_add>.
144
145 $ae->adata_add($aad_data); #can be called multiple times
143146
144147 =head2 encrypt_add
145148
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use base qw(Crypt::AuthEnc Exporter);
77 our %EXPORT_TAGS = ( all => [qw( ocb_encrypt_authenticate ocb_decrypt_verify )] );
1818 my $key = shift;
1919 my $nonce = shift;
2020 my $adata = shift;
21 my $tag_len = shift;
2122 my $plaintext = shift;
2223
23 my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce);
24 $m->aad_add($adata) if defined $adata;
24 my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce, $tag_len);
25 $m->adata_add($adata) if defined $adata;
2526 my $ct = $m->encrypt_last($plaintext);
2627 my $tag = $m->encrypt_done;
2728 return ($ct, $tag);
3536 my $ciphertext = shift;
3637 my $tag = shift;
3738
38 my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce);
39 $m->aad_add($adata) if defined $adata;
39 my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce, length($tag));
40 $m->adata_add($adata) if defined $adata;
4041 my $ct = $m->decrypt_last($ciphertext);
4142 return $m->decrypt_done($tag) ? $ct : undef;
4243 }
4344
44 sub adata_add {
45 # obsolete, only for backwards compatibility
46 shift->aad_add(@_);
47 }
45 # obsolete, only for backwards compatibility
46 sub aad_add { goto &adata_add }
4847
4948 1;
5049
6059 use Crypt::AuthEnc::OCB;
6160
6261 # encrypt and authenticate
63 my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce);
64 $ae->aad_add('additional_authenticated_data1');
65 $ae->aad_add('additional_authenticated_data2');
62 my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce, $tag_len);
63 $ae->adata_add('additional_authenticated_data1');
64 $ae->adata_add('additional_authenticated_data2');
6665 $ct = $ae->encrypt_add('data1');
6766 $ct = $ae->encrypt_add('data2');
6867 $ct = $ae->encrypt_add('data3');
7069 ($ct,$tag) = $ae->encrypt_done();
7170
7271 # decrypt and verify
73 my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce);
74 $ae->aad_add('additional_authenticated_data1');
75 $ae->aad_add('additional_authenticated_data2');
72 my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce, $tag_len);
73 $ae->adata_add('additional_authenticated_data1');
74 $ae->adata_add('additional_authenticated_data2');
7675 $pt = $ae->decrypt_add('ciphertext1');
7776 $pt = $ae->decrypt_add('ciphertext2');
7877 $pt = $ae->decrypt_add('ciphertext3');
8281 ### functional interface
8382 use Crypt::AuthEnc::OCB qw(ocb_encrypt_authenticate ocb_decrypt_verify);
8483
85 my ($ciphertext, $tag) = ocb_encrypt_authenticate('AES', $key, $nonce, $adata, $plaintext);
84 my ($ciphertext, $tag) = ocb_encrypt_authenticate('AES', $key, $nonce, $adata, $tag_len, $plaintext);
8685 my $plaintext = ocb_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
8786
8887 =head1 DESCRIPTION
8988
90 This module implements OCB version 3 according http://datatracker.ietf.org/doc/draft-irtf-cfrg-ocb/
89 This module implements OCB v3 according to L<https://tools.ietf.org/html/rfc7253>
9190
9291 =head1 EXPORT
9392
101100
102101 =head2 ocb_encrypt_authenticate
103102
104 my ($ciphertext, $tag) = ocb_encrypt_authenticate($cipher, $key, $nonce, $adata, $plaintext);
103 my ($ciphertext, $tag) = ocb_encrypt_authenticate($cipher, $key, $nonce, $adata, $tag_len, $plaintext);
105104
106105 # $cipher .. 'AES' or name of any other cipher with 16-byte block len
107106 # $key ..... AES key of proper length (128/192/256bits)
108107 # $nonce ... unique nonce/salt (no need to keep it secret)
109108 # $adata ... additional authenticated data
109 # $tag_len . required length of output tag
110110
111111 =head2 ocb_decrypt_verify
112112
118118
119119 =head2 new
120120
121 my $ae = Crypt::AuthEnc::OCB->new($cipher, $key, $nonce);
121 my $ae = Crypt::AuthEnc::OCB->new($cipher, $key, $nonce, $tag_len);
122122
123123 # $cipher .. 'AES' or name of any other cipher with 16-byte block len
124124 # $key ..... AES key of proper length (128/192/256bits)
125125 # $nonce ... unique nonce/salt (no need to keep it secret)
126 # $tag_len . required length of output tag
126127
127 =head2 aad_add
128 =head2 adata_add
128129
129 $ae->aad_add($adata); #can be called multiple times
130 $ae->adata_add($adata); #can be called multiple times
130131
131132 =head2 encrypt_add
132133
168169
169170 =item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>
170171
171 =item * L<https://en.wikipedia.org/wiki/OCB_mode|https://en.wikipedia.org/wiki/OCB_mode>
172 =item * L<https://en.wikipedia.org/wiki/OCB_mode>
173
174 =item * L<https://tools.ietf.org/html/rfc7253>
172175
173176 =back
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 sub CLONE_SKIP { 1 } # prevent cloning
77
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55 use Carp;
66 use CryptX;
77
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55 use Carp;
66 use CryptX;
77
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
77 our %EXPORT_TAGS = ( all => [qw/
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('AES');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::AES;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Anubis');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Anubis;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Blowfish');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Blowfish;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('CAST5');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::CAST5;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Camellia');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Camellia;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('DES');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::DES;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('DES_EDE');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::DES_EDE;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('KASUMI');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::KASUMI;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Khazad');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Khazad;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('MULTI2');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::MULTI2;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Noekeon');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Noekeon;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
2020
2121 =head1 NAME
2222
23 Crypt::Cipher::RC2 - Symetric cipher RC2, key size: 64-1024 bits (Crypt::CBC compliant)
23 Crypt::Cipher::RC2 - Symetric cipher RC2, key size: 40-1024 bits (Crypt::CBC compliant)
2424
2525 =head1 SYNOPSIS
2626
3232 my $cbc = Crypt::Mode::CBC->new('RC2');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::RC2;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('RC5');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::RC5;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('RC6');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::RC6;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SAFERP');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SAFERP;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SAFER_K128');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SAFER_K128;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SAFER_K64');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SAFER_K64;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SAFER_SK128');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SAFER_SK128;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SAFER_SK64');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SAFER_SK64;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('SEED');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::SEED;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Skipjack');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Skipjack;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('Twofish');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::Twofish;
3838
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use CryptX;
99 use base 'Crypt::Cipher';
3232 my $cbc = Crypt::Mode::CBC->new('XTEA');
3333 my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
3434
35 ### example 2
35 ### example 2 (slower)
3636 use Crypt::CBC;
3737 use Crypt::Cipher::XTEA;
3838
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55 use CryptX;
66
77 ### the following methods/functions are implemented in XS:
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2b_160 blake2b_160_hex blake2b_160_b64 blake2b_160_b64u blake2b_160_file blake2b_160_file_hex blake2b_160_file_b64 blake2b_160_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2b_256 blake2b_256_hex blake2b_256_b64 blake2b_256_b64u blake2b_256_file blake2b_256_file_hex blake2b_256_file_b64 blake2b_256_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2b_384 blake2b_384_hex blake2b_384_b64 blake2b_384_b64u blake2b_384_file blake2b_384_file_hex blake2b_384_file_b64 blake2b_384_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2b_512 blake2b_512_hex blake2b_512_b64 blake2b_512_b64u blake2b_512_file blake2b_512_file_hex blake2b_512_file_b64 blake2b_512_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2s_128 blake2s_128_hex blake2s_128_b64 blake2s_128_b64u blake2s_128_file blake2s_128_file_hex blake2s_128_file_b64 blake2s_128_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2s_160 blake2s_160_hex blake2s_160_b64 blake2s_160_b64u blake2s_160_file blake2s_160_file_hex blake2s_160_file_b64 blake2s_160_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2s_224 blake2s_224_hex blake2s_224_b64 blake2s_224_b64u blake2s_224_file blake2s_224_file_hex blake2s_224_file_b64 blake2s_224_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2s_256 blake2s_256_hex blake2s_256_b64 blake2s_256_b64u blake2s_256_file blake2s_256_file_hex blake2s_256_file_b64 blake2s_256_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( chaes chaes_hex chaes_b64 chaes_b64u chaes_file chaes_file_hex chaes_file_b64 chaes_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( md2 md2_hex md2_b64 md2_b64u md2_file md2_file_hex md2_file_b64 md2_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( md4 md4_hex md4_b64 md4_b64u md4_file md4_file_hex md4_file_b64 md4_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( md5 md5_hex md5_b64 md5_b64u md5_file md5_file_hex md5_file_b64 md5_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( ripemd128 ripemd128_hex ripemd128_b64 ripemd128_b64u ripemd128_file ripemd128_file_hex ripemd128_file_b64 ripemd128_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( ripemd160 ripemd160_hex ripemd160_b64 ripemd160_b64u ripemd160_file ripemd160_file_hex ripemd160_file_b64 ripemd160_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( ripemd256 ripemd256_hex ripemd256_b64 ripemd256_b64u ripemd256_file ripemd256_file_hex ripemd256_file_b64 ripemd256_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( ripemd320 ripemd320_hex ripemd320_b64 ripemd320_b64u ripemd320_file ripemd320_file_hex ripemd320_file_b64 ripemd320_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha1 sha1_hex sha1_b64 sha1_b64u sha1_file sha1_file_hex sha1_file_b64 sha1_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha224 sha224_hex sha224_b64 sha224_b64u sha224_file sha224_file_hex sha224_file_b64 sha224_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha256 sha256_hex sha256_b64 sha256_b64u sha256_file sha256_file_hex sha256_file_b64 sha256_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha384 sha384_hex sha384_b64 sha384_b64u sha384_file sha384_file_hex sha384_file_b64 sha384_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha3_224 sha3_224_hex sha3_224_b64 sha3_224_b64u sha3_224_file sha3_224_file_hex sha3_224_file_b64 sha3_224_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha3_256 sha3_256_hex sha3_256_b64 sha3_256_b64u sha3_256_file sha3_256_file_hex sha3_256_file_b64 sha3_256_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha3_384 sha3_384_hex sha3_384_b64 sha3_384_b64u sha3_384_file sha3_384_file_hex sha3_384_file_b64 sha3_384_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha3_512 sha3_512_hex sha3_512_b64 sha3_512_b64u sha3_512_file sha3_512_file_hex sha3_512_file_b64 sha3_512_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha512 sha512_hex sha512_b64 sha512_b64u sha512_file sha512_file_hex sha512_file_b64 sha512_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha512_224 sha512_224_hex sha512_224_b64 sha512_224_b64u sha512_224_file sha512_224_file_hex sha512_224_file_b64 sha512_224_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( sha512_256 sha512_256_hex sha512_256_b64 sha512_256_b64u sha512_256_file sha512_256_file_hex sha512_256_file_b64 sha512_256_file_b64u )] );
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 use Carp;
77 $Carp::Internal{(__PACKAGE__)}++;
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( tiger192 tiger192_hex tiger192_b64 tiger192_b64u tiger192_file tiger192_file_hex tiger192_file_b64 tiger192_file_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Digest Exporter);
99 our %EXPORT_TAGS = ( all => [qw( whirlpool whirlpool_hex whirlpool_b64 whirlpool_b64u whirlpool_file whirlpool_file_hex whirlpool_file_b64 whirlpool_file_b64u )] );
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
77 our %EXPORT_TAGS = ( all => [qw( digest_data digest_data_hex digest_data_b64 digest_data_b64u digest_file digest_file_hex digest_file_b64 digest_file_b64u )] );
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
77 our %EXPORT_TAGS = ( all => [qw(pbkdf1 pbkdf2 hkdf hkdf_expand hkdf_extract)] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2b blake2b_hex blake2b_b64 blake2b_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( blake2s blake2s_hex blake2s_b64 blake2s_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( f9 f9_hex f9_b64 f9_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( hmac hmac_hex hmac_b64 hmac_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( omac omac_hex omac_b64 omac_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( pmac pmac_hex pmac_b64 pmac_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( pelican pelican_hex pelican_b64 pelican_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u )] );
33
44 use strict;
55 use warnings;
6 our $VERSION = '0.048';
6 our $VERSION = '0.054';
77
88 use base qw(Crypt::Mac Exporter);
99 our %EXPORT_TAGS = ( all => [qw( xcbc xcbc_hex xcbc_b64 xcbc_b64u )] );
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
77 our %EXPORT_TAGS = ( all => [qw( mac mac_hex )] );
4747
4848 =head1 NAME
4949
50 Crypt::mode - [internal only]
50 Crypt::Mac - [internal only]
5151
5252 =cut
11
22 use strict;
33 use warnings;
4 our $VERSION = '0.048';
4 our $VERSION = '0.054';
55
66 require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
77 use Carp 'croak';
8 our %EXPORT_TAGS = ( all => [qw(encode_b64 decode_b64 encode_b64u decode_b64u
9 pem_to_der der_to_pem
10 read_rawfile write_rawfile
8 our %EXPORT_TAGS = ( all => [qw(encode_b64 decode_b64
9 encode_b64u decode_b64u
10 encode_b58b decode_b58b
11 encode_b58f decode_b58f
12 encode_b58r decode_b58r
13 encode_b58t decode_b58t
14 encode_b58s decode_b58s
15 encode_b32r decode_b32r
16 encode_b32b decode_b32b
17 encode_b32z decode_b32z
18 encode_b32c decode_b32c
19 pem_to_der der_to_pem
20 read_rawfile write_rawfile
1121 slow_eq is_v4uuid random_v4uuid
1222 increment_octets_be increment_octets_le
1323 )] );
4050 CryptX::_decode_base64url(@_);
4151 }
4252
53 sub _encode_b58 {
54 my ($bytes, $alphabet) = @_;
55
56 return '' if !defined $bytes || length($bytes) == 0;
57
58 # handle leading zero-bytes
59 my $base58 = '';
60 if ($bytes =~ /^(\x00+)/) {
61 $base58 = ('0' x length($1));
62 }
63 $base58 .= CryptX::_bin_to_radix($bytes, 58);
64
65 if (defined $alphabet) {
66 my $default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv";
67 return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/;
68 eval "\$base58 =~ tr/$default/$alphabet/"; # HACK: https://stackoverflow.com/questions/11415045/using-a-char-variable-in-tr
69 return undef if $@;
70 }
71
72 return $base58;
73 }
74
75 sub _decode_b58 {
76 my ($base58, $alphabet) = @_;
77
78 return '' if !defined $base58 || length($base58) == 0;
79
80 my $default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv";
81 if (defined $alphabet) {
82 return undef if $alphabet !~ /^[a-zA-Z0-9]{58}$/;
83 eval "\$base58 =~ tr/$alphabet/$default/"; # HACK: https://stackoverflow.com/questions/11415045/using-a-char-variable-in-tr
84 return undef if $@;
85 }
86 return undef if $base58 !~ /^[$default]+$/;
87
88 # handle leading zeroes
89 my $bytes = '';
90 if ($base58 =~ /^(0+)(.*)$/) {
91 $base58 = $2;
92 $bytes = ("\x00" x length($1));
93 }
94 $bytes .= CryptX::_radix_to_bin($base58, 58) if defined $base58 && length($base58) > 0;
95
96 return $bytes;
97 }
98
99 sub decode_b58b { _decode_b58(shift, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") } # Bitcoin
100 sub decode_b58f { _decode_b58(shift, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") } # Flickr
101 sub decode_b58r { _decode_b58(shift, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") } # Ripple
102 sub decode_b58t { _decode_b58(shift, "RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz") } # Tipple
103 sub decode_b58s { _decode_b58(shift, "gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz") } # Stellar
104
105 sub encode_b58b { _encode_b58(shift, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") } # Bitcoin
106 sub encode_b58f { _encode_b58(shift, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") } # Flickr
107 sub encode_b58r { _encode_b58(shift, "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") } # Ripple
108 sub encode_b58t { _encode_b58(shift, "RPShNAF39wBUDnEGHJKLM4pQrsT7VWXYZ2bcdeCg65jkm8ofqi1tuvaxyz") } # Tipple
109 sub encode_b58s { _encode_b58(shift, "gsphnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCr65jkm8oFqi1tuvAxyz") } # Stellar
110
111 sub encode_b32r { CryptX::_encode_b32(shift, 0) } # rfc4648
112 sub encode_b32b { CryptX::_encode_b32(shift, 1) } # base32hex
113 sub encode_b32z { CryptX::_encode_b32(shift, 2) } # zbase32
114 sub encode_b32c { CryptX::_encode_b32(shift, 3) } # crockford
115
116 sub decode_b32r { CryptX::_decode_b32(shift, 0) } # rfc4648
117 sub decode_b32b { CryptX::_decode_b32(shift, 1) } # base32hex
118 sub decode_b32z { CryptX::_decode_b32(shift, 2) } # zbase32
119 sub decode_b32c { CryptX::_decode_b32(shift, 3) } # crockford
120
121
43122 sub increment_octets_be {
44123 CryptX::_increment_octets_be(@_);
45124 #$_[0] = CryptX::_increment_octets_be($_[0]);
53132 sub pem_to_der {
54133 my ($data, $password) = @_;
55134
56 my ($begin, $obj1, $content, $end, $obj2) = $data =~ m/(----[- ]BEGIN ([^\r\n\-]+KEY)[ -]----)(.*?)(----[- ]END ([^\r\n\-]+)[ -]----)/s;
135 my ($begin, $obj1, $content, $end, $obj2);
136 # first try to load KEY (e.g. EC pem files might contain more parts)
137 ($begin, $obj1, $content, $end, $obj2) = $data =~ m/(----[- ]BEGIN ([^\r\n\-]+KEY)[ -]----)(.*?)(----[- ]END ([^\r\n\-]+)[ -]----)/s;
138 # if failed then try to load anything
139 ($begin, $obj1, $content, $end, $obj2) = $data =~ m/(----[- ]BEGIN ([^\r\n\-]+)[ -]----)(.*?)(----[- ]END ([^\r\n\-]+)[ -]----)/s unless $content;
57140 return undef unless $content;
58141
59142 $content =~ s/^\s+//sg;
234317
235318 use Crypt::Misc ':all';
236319
237 =head2 encode_b64
238
239 I<Since: CryptX-0.029>
240
241 $base64string = encode_b64($rawdata);
242
243 Encode $rawbytes into Base64 string, no line-endings in the output string.
244
245 =head2 decode_b64
246
247 I<Since: CryptX-0.029>
248
249 $rawdata = encode_b64($base64string);
250
251 Decode a Base64 string.
252
253 =head2 encode_b64u
254
255 I<Since: CryptX-0.029>
256
257 $base64url_string = encode_b64($rawdata);
258
259 Encode $rawbytes into Base64/URL-Safe string, no line-endings in the output string.
260
261 =head2 decode_b64u
262
263 I<Since: CryptX-0.029>
264
265 $rawdata = encode_b64($base64url_string);
266
267 Decode a Base64/URL-Safe string.
268
269320 =head2 read_rawfile
270321
271 I<Since: CryptX-0.029>
322 I<Since: 0.029>
272323
273324 $rawdata = read_rawfile($filename);
274325
276327
277328 =head2 write_rawfile
278329
279 I<Since: CryptX-0.029>
330 I<Since: 0.029>
280331
281332 write_rawfile($filename, $rawdata);
282333
283 Write C<$rawdata> to file <$filename> as binary data.
334 Write C<$rawdata> to file C<$filename> as binary data.
284335
285336 =head2 slow_eq
286337
287 I<Since: CryptX-0.029>
338 I<Since: 0.029>
288339
289340 if (slow_eq($data1, $data2)) { ... }
290341
292343
293344 =head2 pem_to_der
294345
295 I<Since: CryptX-0.029>
346 I<Since: 0.029>
296347
297348 $der_data = pem_to_der($pem_data);
298349 #or
302353
303354 =head2 der_to_pem
304355
305 I<Since: CryptX-0.029>
306
307 $pem_data = der_to_pem($pem_data, $header_name);
356 I<Since: 0.029>
357
358 $pem_data = der_to_pem($der_data, $header_name);
308359 #or
309 $pem_data = der_to_pem($pem_data, $header_name, $password);
360 $pem_data = der_to_pem($der_data, $header_name, $password);
310361 #or
311 $pem_data = der_to_pem($pem_data, $header_name, $passord, $cipher_name);
362 $pem_data = der_to_pem($der_data, $header_name, $passord, $cipher_name);
312363
313364 # $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ...
314365 # $cipher_name e.g. "DES-EDE3-CBC", "AES-256-CBC" (DEFAULT) ...
317368
318369 =head2 random_v4uuid
319370
320 I<Since: CryptX-0.031>
371 I<Since: 0.031>
321372
322373 my $uuid = random_v4uuid();
323374
327378
328379 =head2 is_v4uuid
329380
330 I<Since: CryptX-0.031>
381 I<Since: 0.031>
331382
332383 if (is_v4uuid($uuid)) {
333384 ...
337388
338389 =head2 increment_octets_le
339390
340 I<Since: CryptX-0.048>
391 I<Since: 0.048>
341392
342393 $octects = increment_octets_le($octets);
343394
345396
346397 =head2 increment_octets_be
347398
348 I<Since: CryptX-0.048>
399 I<Since: 0.048>
349400
350401 $octects = increment_octets_be($octets);
351402
352403 Take input C<$octets> as a big-endian big number and return an increment.
353404
405 =head2 encode_b64
406
407 I<Since: 0.029>
408
409 $base64string = encode_b64($rawdata);
410
411 Encode $rawbytes into Base64 string, no line-endings in the output string.
412
413 =head2 decode_b64
414
415 I<Since: 0.029>
416
417 $rawdata = decode_b64($base64string);
418
419 Decode a Base64 string.
420
421 =head2 encode_b64u
422
423 I<Since: 0.029>
424
425 $base64url_string = encode_b64($rawdata);
426
427 Encode $rawbytes into Base64/URL-Safe string, no line-endings in the output string.
428
429 =head2 decode_b64u
430