Codebase list libcryptx-perl / e5c6fb2
v0.029 Karel Miko 8 years ago
6 changed file(s) with 109 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
00 Changes for CryptX
11
22 TODO:
3 - fix - Please specify prototyping behavior for CryptX.xs (see perlxs manual)
34 - add adler32 + crc32 functions
45 - add support for PKCS#8 encrypted RSA+ECC private keys "-----BEGIN ENCRYPTED PRIVATE KEY-----"
56 - RSA|DSA|ECC: verify_key($level) (basic check + extented primality test)
1314 - maybe: add enc_b64/dec_b64 + enc_b64u/dec_b64u + enc_b32/dec_b32
1415 - maybe: x509_rsa_pubkey + x509_rsa_pubkey_alg
1516
16 0.028_04 2016/04/04
17 0.029 2016/04/13
1718 - NEW module: Math::BigInt::LTM
1819 - NEW module: Crypt::Misc
19 - TODO: pod for Crypt::Misc
20 - TODO: fix - Please specify prototyping behavior for CryptX.xs (see perlxs manual)
2120
2221 0.028 2016/03/23
2322 - IMPORTANT: switch from Module::Build to ExtUtils::MakeMaker
66 use Carp 'croak';
77 our %EXPORT_TAGS = ( all => [qw(encode_b64 decode_b64 encode_b64u decode_b64u pem_to_der der_to_pem read_rawfile write_rawfile slow_eq)] );
88 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
9 our @EXPORT = qw();
9 our @EXPORT = qw();
1010
1111 use Carp 'carp';
1212 use CryptX;
160160
161161 =head1 SYNOPSIS
162162
163 This module contains a collection of mostly unsorted functions loosely-related to CryptX distribution but not implementing cryptography.
164
165 Most of them are also available in other perl modules but once you utilize CryptX you might avoid dependencies on other modules by using
166 functions from Crypt::Misc.
167
168 =head1 DESCRIPTION
169
163170 use Crypt::Misc ':all';
164171
165
166 =head1 DESCRIPTION
167
168 xxx
169
170 =head1 METHODS
172 # Base64 and Base64/URL-safe functions
173 $base64 = encode_b64($rawbytes);
174 $rawbytes = decode_b64($base64);
175 $base64url = encode_b64u($encode_b64u);
176 $rawbytes = decode_b64u($base64url);
177
178 # read/write file
179 $rawdata = read_rawfile($filename);
180 write_rawfile($filename, $rawdata);
181
182 # convert PEM/DER
183 $der_data = pem_to_der($pem_data);
184 $pem_data = der_to_pem($der_data);
185
186 # others
187 die "mismatch" unless slow_eq($str1, $str2);
188
189 =head1 FUNCTIONS
190
191 By default, Crypt::Misc doesn't import any function. You can import individual functions like this:
192
193 use Crypt::Misc qw(read_rawfile);
194
195 Or import all available functions:
196
197 use Crypt::Misc ':all';
171198
172199 =head2 encode_b64
173200
174 xxx
201 I<Since: CryptX-0.029>
202
203 $base64string = encode_b64($rawdata);
204
205 Encode $rawbytes into Base64 string, no line-endings in the output string.
175206
176207 =head2 decode_b64
177208
178 xxx
209 I<Since: CryptX-0.029>
210
211 $rawdata = encode_b64($base64string);
212
213 Decode a Base64 string.
214
215 =head2 encode_b64u
216
217 I<Since: CryptX-0.029>
218
219 $base64url_string = encode_b64($rawdata);
220
221 Encode $rawbytes into Base64/URL-Safe string, no line-endings in the output string.
222
223 =head2 decode_b64u
224
225 I<Since: CryptX-0.029>
226
227 $rawdata = encode_b64($base64url_string);
228
229 Decode a Base64/URL-Safe string.
179230
180231 =head2 read_rawfile
181232
182 xxx
233 I<Since: CryptX-0.029>
234
235 $rawdata = read_rawfile($filename);
236
237 Read file C<$filename> into a scalar as a binary data (without decoding/transformation).
183238
184239 =head2 write_rawfile
185240
186 xxx
241 I<Since: CryptX-0.029>
242
243 write_rawfile($filename, $rawdata);
244
245 Write C<$rawdata> to file <$filename> as binary data.
187246
188247 =head2 slow_eq
189248
190 xxx
191
192 =head2 encode_b64u
193
194 xxx
195
196 =head2 decode_b64u
197
198 xxx
249 I<Since: CryptX-0.029>
250
251 if (slow_eq($data1, $data2)) { ... }
252
253 Constant time compare (to avoid timing side-channel).
199254
200255 =head2 pem_to_der
201256
202 xxx
257 I<Since: CryptX-0.029>
258
259 $der_data = pem_to_der($pem_data);
260 #or
261 $der_data = pem_to_der($pem_data, $password);
262
263 Convert PEM to DER representation. Supports also password protected PEM data.
203264
204265 =head2 der_to_pem
205266
206 xxx
267 I<Since: CryptX-0.029>
268
269 $pem_data = der_to_pem($pem_data, $header_name);
270 #or
271 $pem_data = der_to_pem($pem_data, $header_name, $password);
272 #or
273 $pem_data = der_to_pem($pem_data, $header_name, $passord, $cipher_name);
274
275 # $header_name e.g. "PUBLIC KEY", "RSA PRIVATE KEY" ...
276 # $cipher_name e.g. "DES-EDE3-CBC", "AES-256-CBC" (DEFAULT) ...
277
278 Convert DER to PEM representation. Supports also password protected PEM data.
207279
208280 =head1 SEE ALSO
209281
214286 =back
215287
216288 =cut
217
218 __END__
10381038
10391039 =head2 export_key_jwk
10401040
1041 I<Since: CryptX-0.022>
1042
10411043 Exports public/private keys as a JSON Web Key (JWK).
10421044
10431045 my $private_json_text = $pk->export_key_jwk('private');
10881090
10891091 =head2 sign_message_rfc7518
10901092
1093 I<Since: CryptX-0.024>
1094
10911095 Same as L<sign_message|/sign_message> only the signature format is as defined by L<https://tools.ietf.org/html/rfc7518>
10921096 (JWA - JSON Web Algorithms).
10931097
11011105 #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest
11021106
11031107 =head2 verify_message_rfc7518
1108
1109 I<Since: CryptX-0.024>
11041110
11051111 Same as L<verify_message|/verify_message> only the signature format is as defined by L<https://tools.ietf.org/html/rfc7518>
11061112 (JWA - JSON Web Algorithms).
11671173
11681174 =head2 curve2hash
11691175
1176 I<Since: CryptX-0.024>
1177
11701178 my $crv = $pk->curve2hash;
11711179
11721180 # returns a hash that can be passed to: $pk->generate_key($crv)
552552
553553 =head2 export_key_jwk
554554
555 I<Since: CryptX-0.022>
556
555557 Exports public/private keys as a JSON Web Key (JWK).
556558
557559 my $private_json_text = $pk->export_key_jwk('private');
22 use strict;
33 use warnings ;
44
5 our $VERSION = '0.028_04';
5 our $VERSION = '0.029';
66
77 use base qw(Exporter);
88 our @EXPORT_OK = qw( _decode_json _encode_json);
204204
205205 Provides support for big integer calculations by means of the libtommath c-library.
206206
207 I<Since: CryptX-0.029>
208
207209 =head1 SEE ALSO
208210
209211 L<Math::BigInt>, L<https://github.com/libtom/libtommath>