Imported Upstream version 0.048
This commit is contained in:
commit
8a5223aec1
249
Changes
Normal file
249
Changes
Normal file
@ -0,0 +1,249 @@
|
||||
Changes for CryptX
|
||||
|
||||
TODO:
|
||||
- add support for PKCS#8 encrypted RSA+ECC private keys "-----BEGIN ENCRYPTED PRIVATE KEY-----"
|
||||
- RSA|DSA|ECC: verify_key($level) (basic check + extented primality test)
|
||||
- better primality testing: http://questhub.io/realm/perl/quest/519032ee1088c76505000035 (idea: mp_prime_lucas)
|
||||
- DSA: generate_key($p, $q, $g), generate_key(\$dsa_params_der), generate_key($dsa_params_file)
|
||||
- XS croaks should report the "real caller" (Crypt::Mac::*, Crypt::Mode::*, ...)
|
||||
- maybe: add CCM interface for new-add-add-done mode
|
||||
- maybe: add encode_b32/decode_b32
|
||||
|
||||
0.048 2017/05/31
|
||||
- NEW: Crypt::Digest::SHA3_224
|
||||
- NEW: Crypt::Digest::SHA3_256
|
||||
- NEW: Crypt::Digest::SHA3_384
|
||||
- NEW: Crypt::Digest::SHA3_512
|
||||
- NEW: Crypt::Digest::SHAKE
|
||||
- NEW: Crypt::Digest::BLAKE2b_160
|
||||
- NEW: Crypt::Digest::BLAKE2b_256
|
||||
- NEW: Crypt::Digest::BLAKE2b_384
|
||||
- NEW: Crypt::Digest::BLAKE2b_512
|
||||
- NEW: Crypt::Digest::BLAKE2s_128
|
||||
- NEW: Crypt::Digest::BLAKE2s_160
|
||||
- NEW: Crypt::Digest::BLAKE2s_224
|
||||
- NEW: Crypt::Digest::BLAKE2s_256
|
||||
- NEW: Crypt::AuthEnc::ChaCha20Poly1305
|
||||
- NEW: Crypt::Mac::Poly1305
|
||||
- NEW: Crypt::Mac::BLAKE2s
|
||||
- NEW: Crypt::Mac::BLAKE2b
|
||||
- NEW: Crypt::PRNG::ChaCha20
|
||||
- NEW: Crypt::Stream::ChaCha
|
||||
- NEW: Crypt::Stream::RC4
|
||||
- NEW: Crypt::Stream::Sober128
|
||||
- NEW: functions in Crypt::Misc - increment_octets_be, increment_octets_le
|
||||
- Crypt::PRNG now uses chacha20 prng by default
|
||||
|
||||
0.047 2017/04/05
|
||||
- fix #32 Compile "ar" step fails when Perl built with -flto (better version)
|
||||
- fix #33 build fails on freebsd 9.2 and 10.0 (ar: fatal: Numeric group ID too large)
|
||||
|
||||
0.046 2017/04/04
|
||||
- fix #32 Compile "ar" step fails when Perl built with -flto
|
||||
|
||||
0.045 2017/03/31
|
||||
- sync with libtomcrypt/develop
|
||||
- fix #30 fix on SPARC+SolarisStudio
|
||||
- fix #31 Fails tests without '.' in @INC
|
||||
- polish compiler warnings
|
||||
|
||||
0.044 2016/11/28
|
||||
- fix #27 Math::BigInt::LTM compatibility with older Math::BigInt
|
||||
|
||||
0.043 2016/11/27
|
||||
- fix #26 Math::BigInt::LTM compatibility with Math::BigInt 1.999801+
|
||||
|
||||
0.042 2016/11/12
|
||||
- RSA: sign/verify functions now support 'none' padding (INSECURE!)
|
||||
- RC2: min keylen 40bit, used to be 64bit (INSECURE!)
|
||||
|
||||
0.041 2016/10/12
|
||||
- ECC: ltc_ecc_is_point memory leak
|
||||
- DSA: properly handle FIPS 186-4 (4.6 + 4.7)
|
||||
- GCM: counter incrementation isn't stopped at 2^32 blocks, which breaks GCM
|
||||
- fix issue #24 Crypt::PK::ECC needs $VERSION (all *.pm have $VERSION)
|
||||
|
||||
0.040 2016/09/12
|
||||
- fix file permissions
|
||||
- fix compiler warnings
|
||||
|
||||
0.039 2016/08/02
|
||||
- fix build troubles for MacOS / PPC
|
||||
|
||||
0.038 2016/07/06
|
||||
- fix issue #20 DSA/RSA/ECC/DH key2hash - hexadecimal numbers are missing leading zero
|
||||
- Math::BigInt::LTM fixed mp_invmod(a,b,c) for b == 1
|
||||
- Math::BigInt::LTM fixed _log_int()
|
||||
- Math::BigInt::LTM fixed _alen()
|
||||
- fix 'Please specify prototyping behavior for CryptX.xs'
|
||||
- libtomcrypt (renaming *tab.c > *tab.c.inc not needed anymore)
|
||||
|
||||
0.037 2016/06/16
|
||||
- fix issue #18 Minor issue with comment syntax
|
||||
- fix issue #19 t/checksum.t fails on AIX-5.3
|
||||
|
||||
0.036 2016/06/07
|
||||
- fix issue #17 ability to export ecc keys in short/oid form
|
||||
|
||||
0.035 2016/06/03
|
||||
- fix issue #14 Ensure Crypt::PK::ECC->key2hash()->{curve_name} is lowercase
|
||||
- fix issue #15 OpenSSL interoperability broken
|
||||
|
||||
0.034 2016/05/11
|
||||
- Prevent RSA import_key() from altering a JWK hash reference
|
||||
|
||||
0.033 2016/05/09
|
||||
- MSVC6 related fixes (needed for older ActivePerl@MSWin32)
|
||||
|
||||
0.032 2016/05/04
|
||||
- Crypt::PK::DH - accept base/prime values
|
||||
- new: DH methods export_key_raw, import_key_raw, params2hash
|
||||
- enhanced: DH method generate_key
|
||||
- new: Crypt::Checksum, Crypt::Checksum::CRC32, Crypt::Checksum::Adler32
|
||||
|
||||
0.031 2016/05/01
|
||||
- new: RSA+ECC method export_key_jwk_thumbprint()
|
||||
- new: Crypt::Misc functions random_v4uuid + is_v4uuid
|
||||
- fix: RSA+ECC export_key_jwk produces canonical JSON
|
||||
- fix: RSA+DSA public key export now produces PEM/DER compatible with openssl
|
||||
public keys exported be previous version can still be imported
|
||||
- fix: ECC import_key now accepts non-standard JWK curve names e.g. "secp112r1", "secp521r1"
|
||||
|
||||
0.030 2016/04/13
|
||||
- fix: 0.029 + 0.028 by mistake installed *.inc files to perl/(lib|site|vendor)
|
||||
|
||||
0.029 2016/04/13
|
||||
- NEW module: Math::BigInt::LTM
|
||||
- NEW module: Crypt::Misc
|
||||
|
||||
0.028 2016/03/23
|
||||
- IMPORTANT: switch from Module::Build to ExtUtils::MakeMaker
|
||||
- fix for broken DSA key (ssh format) loading
|
||||
|
||||
0.027 2016/01/25
|
||||
- sync with https://github.com/libtom/libtomcrypt (branch develop)
|
||||
- sync with https://github.com/libtom/libtommath (branch develop)
|
||||
- HP-UX related fixes
|
||||
- JSON dependency is now optional (we check JSON::PP, JSON::XS, Cpanel::JSON::XS)
|
||||
- skip jwk.t if no JSON::* module available
|
||||
- does not require MIME::Base64 (we use base64 routines from libtomcrypt)
|
||||
|
||||
0.026 2015/11/28
|
||||
- switch to JSON::MaybeXS
|
||||
- Crypt::PRNG - rand/irand related cosmetics
|
||||
- consistently using UNIX newlines
|
||||
|
||||
0.025 2015/07/07
|
||||
- Crypt::PK::ECC+RSA export_key_jwk() allows to export a perl HASH with JWK structure
|
||||
|
||||
0.024 2015/06/29
|
||||
- new Crypt::PK::ECC methods
|
||||
verify_message_rfc7518()
|
||||
sign_message_rfc7518()
|
||||
curve2hash()
|
||||
- fix for Crypt::PK::RSA - bug in loading private key in JWK format
|
||||
|
||||
0.023 2015/06/10
|
||||
- support for older compilers (gcc3, vc6)
|
||||
- typo in documentation (by tomhukins)
|
||||
|
||||
0.022 2015/05/22
|
||||
- new: Crypt::PK::ECC+RSA export_key_jwk() - exporting JWK format
|
||||
- new: Crypt::Digest::SHA512_224
|
||||
- new: Crypt::Digest::SHA512_256
|
||||
- Crypt::PK::ECC+RSA import_key() - support for:
|
||||
* public/private keys in JWK format
|
||||
* private keys in PKCS8 PEM/DER format (unencrypted only)
|
||||
- Crypt::PK::ECC+RSA+DSA import_key() - support for:
|
||||
* public keys in SSH format
|
||||
* public/private keys as a hashref exported via key2hash
|
||||
- libtomcrypt updated to the latest develop branch, commit aeaa6d4a51 Apr 17 08:59:35 2015 +0200
|
||||
- libtommath updated to the latest develop branch, commit 0fd5e6c17f Dec 11 14:59:35 2014 +0100
|
||||
- documentation fixes
|
||||
|
||||
0.021 2014/01/23
|
||||
- fixed asm(...) related compiler failures
|
||||
- dsa_encrypt_key small correction
|
||||
- optimized ecc_encrypt_key
|
||||
|
||||
0.020 2014/01/18
|
||||
- INCOMPATIBLE CHANGE: huge redesign of Crypt::PK::ECC
|
||||
- ECC now supports curves y^2 = x^3 + a*x + b
|
||||
- ECC you can use custom curves
|
||||
- ECC import/export of keys in DER/PEM format now compatible with openssl
|
||||
- enabling compile options ASM + ECC_TIMING_RESISTANT
|
||||
- added many test vectors (RSA, DSA, EC) for interoperability with openssl
|
||||
|
||||
0.019 2013/10/20
|
||||
- fixed broken CAMELLIA implementation
|
||||
|
||||
0.018 2013/10/18
|
||||
- DSA: make_key + sign_hash fixes
|
||||
|
||||
0.017 2013/09/24
|
||||
- lowering MIME::Base64 version requirement
|
||||
- support for import/export of password protected RSA/DSA keys
|
||||
- RSA: added - export_key_pem('public_x509')
|
||||
- better handling of dh_free/rsa_free/dsa_free/ecc_free
|
||||
- added openssl test vectors
|
||||
- fixed compiler warnings (RSA/DSA/ECC/DH)
|
||||
|
||||
0.016 2013/09/15
|
||||
- added missing test for key2hash, sign_hash, verify_hash
|
||||
- fixed build failures on VC6
|
||||
|
||||
0.015 2013/09/12
|
||||
- only documentation fixes
|
||||
|
||||
0.014 2013/09/11
|
||||
- Crypt::Digest::NNN + Crypt::Mac::NNN - can produce Base64-URL-Safe encoded digest/mac
|
||||
- Crypt::PRNG + Crypt::PRNG::NNN - Base64-URL-Safe encoded random bytes (random_bytes_b64u/bytes_b64u)
|
||||
- Crypt::PK::RSA/DSA/DH/ECC - sign/verify replaced by sign_message/verify_message + sign_hash/verify_hash
|
||||
- Crypt::PK::RSA/DSA/DH/ECC - new method key2hash
|
||||
- documentation fixes
|
||||
|
||||
0.013 2013/08/28
|
||||
- DSA/RSA/ECC/DH - importing keys from string changed - now: $pk->import_key(\$buffer_with_key)
|
||||
- DSA/RSA/ECC/DH - size() and is_private() now return undef if no key loaded
|
||||
- improved RSA doc
|
||||
|
||||
0.012 2013/06/17
|
||||
- README, LICENSE etc. to improve CPANTS score
|
||||
- somehow works with perl 5.6.2
|
||||
|
||||
0.011 2013/06/15
|
||||
- fixing various compiler warnings
|
||||
|
||||
0.009 2013/05/19
|
||||
- doc fixes
|
||||
- requires perl 5.8.8 or higher
|
||||
- INCOMPATIBILITY: all digest related 'xxx_base64' functions renamed to 'xxx_b64'
|
||||
|
||||
0.008 2013/05/02
|
||||
- fixed prng test failures
|
||||
- Crypt::Digest::* croaks with the "real caller" (not a nice solution)
|
||||
|
||||
0.007 2013/04/23
|
||||
- Crypt::PRNG supports add_entropy() - without params
|
||||
- Crypt::PRNG fork-safe & thread-safe
|
||||
- random_string has default $len = 20
|
||||
- doc fixes
|
||||
- cpan tester failure fix for pk_dsa.t
|
||||
|
||||
0.006 2013/04/19
|
||||
- added Crypt::KeyDerivation
|
||||
- Win64 compatibility
|
||||
|
||||
0.005 2013/04/18
|
||||
- added Crypt::PRNG::Fortuna|RC4|Sober128|Yarrow
|
||||
- added Crypt::PK::RSA|DSA|ECC|DH
|
||||
|
||||
0.004 2013/04/16
|
||||
- removing illegal Crypt::Random
|
||||
|
||||
0.003 2013/04/16
|
||||
- added Crypt::Mode::CBC|CFB|CTR|ECB|OFB
|
||||
- added Crypt::AuthEnc::CCM|EAX|GCM|OCB
|
||||
|
||||
0.002 2013/04/11
|
||||
- first release on CPAN
|
580
CryptX.xs
Normal file
580
CryptX.xs
Normal file
@ -0,0 +1,580 @@
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
|
||||
#define NEED_sv_2pvbyte_GLOBAL
|
||||
#define NEED_sv_2pv_flags_GLOBAL
|
||||
#define NEED_newRV_noinc_GLOBAL
|
||||
#include "ppport.h"
|
||||
|
||||
#undef LTC_SOURCE
|
||||
#include "tomcrypt.h"
|
||||
#include "tommath.h"
|
||||
|
||||
typedef adler32_state *Crypt__Checksum__Adler32;
|
||||
typedef crc32_state *Crypt__Checksum__CRC32;
|
||||
|
||||
typedef struct cipher_struct { /* used by Crypt::Cipher */
|
||||
symmetric_key skey;
|
||||
int id;
|
||||
struct ltc_cipher_descriptor *desc;
|
||||
} *Crypt__Cipher;
|
||||
|
||||
typedef struct digest_struct { /* used by Crypt::Digest */
|
||||
hash_state state;
|
||||
int id;
|
||||
struct ltc_hash_descriptor *desc;
|
||||
} *Crypt__Digest;
|
||||
|
||||
typedef struct digest_shake_struct { /* used by Crypt::Digest::SHAKE */
|
||||
hash_state state;
|
||||
int num;
|
||||
} *Crypt__Digest__SHAKE;
|
||||
|
||||
typedef struct ccm_struct { /* used by Crypt::AuthEnc::CCM */
|
||||
ccm_state state;
|
||||
int id;
|
||||
} *Crypt__AuthEnc__CCM;
|
||||
|
||||
typedef struct eax_struct { /* used by Crypt::AuthEnc::EAX */
|
||||
eax_state state;
|
||||
int id;
|
||||
} *Crypt__AuthEnc__EAX;
|
||||
|
||||
typedef struct gcm_struct { /* used by Crypt::AuthEnc::GCM */
|
||||
gcm_state state;
|
||||
int id;
|
||||
} *Crypt__AuthEnc__GCM;
|
||||
|
||||
typedef struct chacha20poly1305_struct {/* used by Crypt::AuthEnc::ChaCha20Poly1305 */
|
||||
chacha20poly1305_state state;
|
||||
int id;
|
||||
} *Crypt__AuthEnc__ChaCha20Poly1305;
|
||||
|
||||
typedef struct ocb_struct { /* used by Crypt::AuthEnc::OCB */
|
||||
ocb3_state state;
|
||||
int id;
|
||||
} *Crypt__AuthEnc__OCB;
|
||||
|
||||
typedef struct chacha_struct { /* used by Crypt::Stream::ChaCha */
|
||||
chacha_state state;
|
||||
int id;
|
||||
} *Crypt__Stream__ChaCha;
|
||||
|
||||
typedef struct rc4_struct { /* used by Crypt::Stream::RC4 */
|
||||
rc4_state state;
|
||||
int id;
|
||||
} *Crypt__Stream__RC4;
|
||||
|
||||
typedef struct sober128_struct { /* used by Crypt::Stream::Sober128 */
|
||||
sober128_state state;
|
||||
int id;
|
||||
} *Crypt__Stream__Sober128;
|
||||
|
||||
typedef struct f9_struct { /* used by Crypt::Mac::F9 */
|
||||
f9_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__F9;
|
||||
|
||||
typedef struct hmac_struct { /* used by Crypt::Mac::HMAC */
|
||||
hmac_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__HMAC;
|
||||
|
||||
typedef struct omac_struct { /* used by Crypt::Mac::OMAC */
|
||||
omac_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__OMAC;
|
||||
|
||||
typedef struct pelican_struct { /* used by Crypt::Mac::Pelican */
|
||||
pelican_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__Pelican;
|
||||
|
||||
typedef struct pmac_struct { /* used by Crypt::Mac::PMAC */
|
||||
pmac_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__PMAC;
|
||||
|
||||
typedef struct xcbc_struct { /* used by Crypt::Mac::XCBC */
|
||||
xcbc_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__XCBC;
|
||||
|
||||
typedef struct poly1305_struct { /* used by Crypt::Mac::Poly1305 */
|
||||
poly1305_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__Poly1305;
|
||||
|
||||
typedef struct blake2s_struct { /* used by Crypt::Mac::BLAKE2s */
|
||||
blake2smac_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__BLAKE2s;
|
||||
|
||||
typedef struct blake2b_struct { /* used by Crypt::Mac::BLAKE2b */
|
||||
blake2bmac_state state;
|
||||
int id;
|
||||
} *Crypt__Mac__BLAKE2b;
|
||||
|
||||
typedef struct cbc_struct { /* used by Crypt::Mode::CBC */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_CBC state;
|
||||
unsigned char pad[MAXBLOCKSIZE];
|
||||
int padlen;
|
||||
int padding_mode;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__CBC;
|
||||
|
||||
typedef struct ecb_struct { /* used by Crypt::Mode::ECB */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_ECB state;
|
||||
unsigned char pad[MAXBLOCKSIZE];
|
||||
int padlen;
|
||||
int padding_mode;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__ECB;
|
||||
|
||||
typedef struct cfb_struct { /* used by Crypt::Mode::CFB */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_CFB state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__CFB;
|
||||
|
||||
typedef struct ctr_struct { /* used by Crypt::Mode::CTR */
|
||||
int cipher_id, cipher_rounds;
|
||||
int ctr_mode_param;
|
||||
symmetric_CTR state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__CTR;
|
||||
|
||||
typedef struct f8_struct { /* used by Crypt::Mode::F8 */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_F8 state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__F8;
|
||||
|
||||
typedef struct lrw_struct { /* used by Crypt::Mode::LRW */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_LRW state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__LRW;
|
||||
|
||||
typedef struct ofb_struct { /* used by Crypt::Mode::OFB */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_OFB state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__OFB;
|
||||
|
||||
typedef struct xts_struct { /* used by Crypt::Mode::XTS */
|
||||
int cipher_id, cipher_rounds;
|
||||
symmetric_xts state;
|
||||
int direction;
|
||||
int id;
|
||||
} *Crypt__Mode__XTS;
|
||||
|
||||
typedef struct prng_struct { /* used by Crypt::PRNG */
|
||||
prng_state state;
|
||||
struct ltc_prng_descriptor *desc;
|
||||
IV last_pid;
|
||||
int id;
|
||||
} *Crypt__PRNG;
|
||||
|
||||
typedef struct rsa_struct { /* used by Crypt::PK::RSA */
|
||||
prng_state pstate;
|
||||
int pindex;
|
||||
rsa_key key;
|
||||
int id;
|
||||
} *Crypt__PK__RSA;
|
||||
|
||||
typedef struct dsa_struct { /* used by Crypt::PK::DSA */
|
||||
prng_state pstate;
|
||||
int pindex;
|
||||
dsa_key key;
|
||||
int id;
|
||||
} *Crypt__PK__DSA;
|
||||
|
||||
typedef struct dh_struct { /* used by Crypt::PK::DH */
|
||||
prng_state pstate;
|
||||
int pindex;
|
||||
dh_key key;
|
||||
int id;
|
||||
} *Crypt__PK__DH;
|
||||
|
||||
typedef struct ecc_struct { /* used by Crypt::PK::ECC */
|
||||
prng_state pstate;
|
||||
int pindex;
|
||||
ecc_key key;
|
||||
ltc_ecc_set_type dp;
|
||||
int id;
|
||||
} *Crypt__PK__ECC;
|
||||
|
||||
int str_add_leading_zero(char *str, int maxlen, int minlen) {
|
||||
int len;
|
||||
len = (int)strlen(str);
|
||||
if (len > 0 && len % 2 && len < maxlen-2) {
|
||||
memmove(str+1, str, len+1); /* incl. NUL byte */
|
||||
*str = '0'; /* add leading zero */
|
||||
}
|
||||
len = (int)strlen(str);
|
||||
if (len < minlen && minlen < maxlen-1) {
|
||||
memmove(str+(minlen-len), str, len+1); /* incl. NUL byte */
|
||||
memset(str, '0', minlen-len); /* add leading zero */
|
||||
}
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
int mp_tohex_with_leading_zero(mp_int * a, char *str, int maxlen, int minlen) {
|
||||
int rv;
|
||||
if (mp_isneg(a) == MP_YES) {
|
||||
*str = '\0';
|
||||
return MP_VAL;
|
||||
}
|
||||
rv = mp_toradix_n(a, str, 16, maxlen);
|
||||
if (rv != MP_OKAY) {
|
||||
*str = '\0';
|
||||
return rv;
|
||||
}
|
||||
return str_add_leading_zero(str, maxlen, minlen);
|
||||
}
|
||||
|
||||
/* Math::BigInt::LTM related */
|
||||
typedef mp_int * Math__BigInt__LTM;
|
||||
STATIC SV * sv_from_mpi(mp_int *mpi) {
|
||||
SV *obj = newSV(0);
|
||||
sv_setref_pv(obj, "Math::BigInt::LTM", (void*)mpi);
|
||||
return obj;
|
||||
}
|
||||
|
||||
ltc_ecc_set_type* _ecc_set_dp_from_SV(ltc_ecc_set_type *dp, SV *curve)
|
||||
{
|
||||
HV *h;
|
||||
SV *param, **pref;
|
||||
SV **sv_cofactor, **sv_prime, **sv_A, **sv_B, **sv_order, **sv_Gx, **sv_Gy;
|
||||
int err;
|
||||
char *ch_name;
|
||||
STRLEN l_name;
|
||||
|
||||
if (SvPOK(curve)) {
|
||||
ch_name = SvPV(curve, l_name);
|
||||
if ((h = get_hv("Crypt::PK::ECC::curve", 0)) == NULL) croak("FATAL: generate_key_ex: no curve register");
|
||||
if ((pref = hv_fetch(h, ch_name, (U32)l_name, 0)) == NULL) croak("FATAL: generate_key_ex: unknown curve/1 '%s'", ch_name);
|
||||
if (!SvOK(*pref)) croak("FATAL: generate_key_ex: unknown curve/2 '%s'", ch_name);
|
||||
param = *pref;
|
||||
}
|
||||
else if (SvROK(curve)) {
|
||||
param = curve;
|
||||
}
|
||||
else {
|
||||
croak("FATAL: curve has to be a string or a hashref");
|
||||
}
|
||||
|
||||
if ((h = (HV*)(SvRV(param))) == NULL) croak("FATAL: ecparams: param is not valid hashref");
|
||||
|
||||
if ((sv_prime = hv_fetchs(h, "prime", 0)) == NULL) croak("FATAL: ecparams: missing param prime");
|
||||
if ((sv_A = hv_fetchs(h, "A", 0)) == NULL) croak("FATAL: ecparams: missing param A");
|
||||
if ((sv_B = hv_fetchs(h, "B", 0)) == NULL) croak("FATAL: ecparams: missing param B");
|
||||
if ((sv_order = hv_fetchs(h, "order", 0)) == NULL) croak("FATAL: ecparams: missing param order");
|
||||
if ((sv_Gx = hv_fetchs(h, "Gx", 0)) == NULL) croak("FATAL: ecparams: missing param Gx");
|
||||
if ((sv_Gy = hv_fetchs(h, "Gy", 0)) == NULL) croak("FATAL: ecparams: missing param Gy");
|
||||
if ((sv_cofactor = hv_fetchs(h, "cofactor", 0)) == NULL) croak("FATAL: ecparams: missing param cofactor");
|
||||
|
||||
if (!SvOK(*sv_prime )) croak("FATAL: ecparams: undefined param prime");
|
||||
if (!SvOK(*sv_A )) croak("FATAL: ecparams: undefined param A");
|
||||
if (!SvOK(*sv_B )) croak("FATAL: ecparams: undefined param B");
|
||||
if (!SvOK(*sv_order )) croak("FATAL: ecparams: undefined param order");
|
||||
if (!SvOK(*sv_Gx )) croak("FATAL: ecparams: undefined param Gx");
|
||||
if (!SvOK(*sv_Gy )) croak("FATAL: ecparams: undefined param Gy");
|
||||
if (!SvOK(*sv_cofactor)) croak("FATAL: ecparams: undefined param cofactor");
|
||||
|
||||
err = ecc_dp_set( dp,
|
||||
SvPV_nolen(*sv_prime),
|
||||
SvPV_nolen(*sv_A),
|
||||
SvPV_nolen(*sv_B),
|
||||
SvPV_nolen(*sv_order),
|
||||
SvPV_nolen(*sv_Gx),
|
||||
SvPV_nolen(*sv_Gy),
|
||||
(unsigned long)SvUV(*sv_cofactor),
|
||||
NULL, /* we intentionally don't allow setting custom names */
|
||||
NULL /* we intentionally don't allow setting custom OIDs */
|
||||
);
|
||||
return err == CRYPT_OK ? dp : NULL;
|
||||
}
|
||||
|
||||
void _ecc_free_key(ecc_key *key, ltc_ecc_set_type *dp)
|
||||
{
|
||||
if(dp) {
|
||||
ecc_dp_clear(dp);
|
||||
}
|
||||
if (key->type != -1) {
|
||||
ecc_free(key);
|
||||
key->type = -1;
|
||||
key->dp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
MODULE = CryptX PACKAGE = CryptX PREFIX = CryptX_
|
||||
|
||||
PROTOTYPES: DISABLE
|
||||
|
||||
BOOT:
|
||||
if(register_cipher(&blowfish_desc)==-1) { croak("FATAL: cannot register_cipher blowfish"); }
|
||||
if(register_cipher(&rc5_desc)==-1) { croak("FATAL: cannot register_cipher rc5"); }
|
||||
if(register_cipher(&rc6_desc)==-1) { croak("FATAL: cannot register_cipher rc6"); }
|
||||
if(register_cipher(&rc2_desc)==-1) { croak("FATAL: cannot register_cipher rc2"); }
|
||||
if(register_cipher(&saferp_desc)==-1) { croak("FATAL: cannot register_cipher saferp"); }
|
||||
if(register_cipher(&safer_k64_desc)==-1) { croak("FATAL: cannot register_cipher safer_k64"); }
|
||||
if(register_cipher(&safer_k128_desc)==-1) { croak("FATAL: cannot register_cipher safer_k128"); }
|
||||
if(register_cipher(&safer_sk64_desc)==-1) { croak("FATAL: cannot register_cipher safer_sk64"); }
|
||||
if(register_cipher(&safer_sk128_desc)==-1) { croak("FATAL: cannot register_cipher safer_sk128"); }
|
||||
if(register_cipher(&aes_desc)==-1) { croak("FATAL: cannot register_cipher aes"); }
|
||||
if(register_cipher(&xtea_desc)==-1) { croak("FATAL: cannot register_cipher xtea"); }
|
||||
if(register_cipher(&twofish_desc)==-1) { croak("FATAL: cannot register_cipher twofish"); }
|
||||
if(register_cipher(&des_desc)==-1) { croak("FATAL: cannot register_cipher des"); }
|
||||
if(register_cipher(&des3_desc)==-1) { croak("FATAL: cannot register_cipher des3"); }
|
||||
if(register_cipher(&cast5_desc)==-1) { croak("FATAL: cannot register_cipher cast5"); }
|
||||
if(register_cipher(&noekeon_desc)==-1) { croak("FATAL: cannot register_cipher noekeon"); }
|
||||
if(register_cipher(&skipjack_desc)==-1) { croak("FATAL: cannot register_cipher skipjack"); }
|
||||
if(register_cipher(&khazad_desc)==-1) { croak("FATAL: cannot register_cipher khazad"); }
|
||||
if(register_cipher(&anubis_desc)==-1) { croak("FATAL: cannot register_cipher anubis"); }
|
||||
if(register_cipher(&kseed_desc)==-1) { croak("FATAL: cannot register_cipher kseed"); }
|
||||
if(register_cipher(&kasumi_desc)==-1) { croak("FATAL: cannot register_cipher kasumi"); }
|
||||
if(register_cipher(&multi2_desc)==-1) { croak("FATAL: cannot register_cipher multi2"); }
|
||||
if(register_cipher(&camellia_desc)==-1) { croak("FATAL: cannot register_cipher camellia"); }
|
||||
/* --- */
|
||||
if(register_hash(&chc_desc)==-1) { croak("FATAL: cannot register_hash chc_hash"); }
|
||||
if(register_hash(&md2_desc)==-1) { croak("FATAL: cannot register_hash md2"); }
|
||||
if(register_hash(&md4_desc)==-1) { croak("FATAL: cannot register_hash md4"); }
|
||||
if(register_hash(&md5_desc)==-1) { croak("FATAL: cannot register_hash md5"); }
|
||||
if(register_hash(&rmd128_desc)==-1) { croak("FATAL: cannot register_hash rmd128"); }
|
||||
if(register_hash(&rmd160_desc)==-1) { croak("FATAL: cannot register_hash rmd160"); }
|
||||
if(register_hash(&rmd256_desc)==-1) { croak("FATAL: cannot register_hash rmd256"); }
|
||||
if(register_hash(&rmd320_desc)==-1) { croak("FATAL: cannot register_hash rmd320"); }
|
||||
if(register_hash(&sha1_desc)==-1) { croak("FATAL: cannot register_hash sha1"); }
|
||||
if(register_hash(&sha224_desc)==-1) { croak("FATAL: cannot register_hash sha224"); }
|
||||
if(register_hash(&sha256_desc)==-1) { croak("FATAL: cannot register_hash sha256"); }
|
||||
if(register_hash(&sha384_desc)==-1) { croak("FATAL: cannot register_hash sha384"); }
|
||||
if(register_hash(&sha512_desc)==-1) { croak("FATAL: cannot register_hash sha512"); }
|
||||
if(register_hash(&sha512_224_desc)==-1) { croak("FATAL: cannot register_hash sha512_224"); }
|
||||
if(register_hash(&sha512_256_desc)==-1) { croak("FATAL: cannot register_hash sha512_256"); }
|
||||
if(register_hash(&sha3_224_desc)==-1) { croak("FATAL: cannot register_hash sha3_224"); }
|
||||
if(register_hash(&sha3_256_desc)==-1) { croak("FATAL: cannot register_hash sha3_256"); }
|
||||
if(register_hash(&sha3_384_desc)==-1) { croak("FATAL: cannot register_hash sha3_384"); }
|
||||
if(register_hash(&sha3_512_desc)==-1) { croak("FATAL: cannot register_hash sha3_512"); }
|
||||
if(register_hash(&tiger_desc)==-1) { croak("FATAL: cannot register_hash tiger"); }
|
||||
if(register_hash(&whirlpool_desc)==-1) { croak("FATAL: cannot register_hash whirlpool"); }
|
||||
if(register_hash(&blake2b_160_desc)==-1) { croak("FATAL: cannot register_hash blake2b_160"); }
|
||||
if(register_hash(&blake2b_256_desc)==-1) { croak("FATAL: cannot register_hash blake2b_256"); }
|
||||
if(register_hash(&blake2b_384_desc)==-1) { croak("FATAL: cannot register_hash blake2b_384"); }
|
||||
if(register_hash(&blake2b_512_desc)==-1) { croak("FATAL: cannot register_hash blake2b_512"); }
|
||||
if(register_hash(&blake2s_128_desc)==-1) { croak("FATAL: cannot register_hash blake2s_128"); }
|
||||
if(register_hash(&blake2s_160_desc)==-1) { croak("FATAL: cannot register_hash blake2s_160"); }
|
||||
if(register_hash(&blake2s_224_desc)==-1) { croak("FATAL: cannot register_hash blake2s_224"); }
|
||||
if(register_hash(&blake2s_256_desc)==-1) { croak("FATAL: cannot register_hash blake2s_256"); }
|
||||
/* --- */
|
||||
if(chc_register(find_cipher("aes"))==-1) { croak("FATAL: chc_register failed"); }
|
||||
/* --- */
|
||||
if(register_prng(&fortuna_desc)==-1) { croak("FATAL: cannot register_prng fortuna"); }
|
||||
if(register_prng(&yarrow_desc)==-1) { croak("FATAL: cannot register_prng yarrow"); }
|
||||
if(register_prng(&rc4_desc)==-1) { croak("FATAL: cannot register_prng rc4"); }
|
||||
if(register_prng(&sober128_desc)==-1) { croak("FATAL: cannot register_prng sober128"); }
|
||||
if(register_prng(&chacha20_prng_desc)==-1) { croak("FATAL: cannot register_prng chacha20"); }
|
||||
/* --- */
|
||||
#ifdef TFM_DESC
|
||||
ltc_mp = tfm_desc;
|
||||
#else
|
||||
ltc_mp = ltm_desc;
|
||||
#endif
|
||||
|
||||
SV *
|
||||
CryptX__encode_base64url(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN in_len;
|
||||
unsigned long out_len;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, in_len);
|
||||
out_len = (unsigned long)(4 * ((in_len + 2) / 3) + 1);
|
||||
Newz(0, out_data, out_len, unsigned char);
|
||||
if (!out_data) croak("FATAL: Newz failed [%ld]", out_len);
|
||||
rv = base64url_encode(in_data, (unsigned long)in_len, out_data, &out_len);
|
||||
RETVAL = (rv == CRYPT_OK) ? newSVpvn((char *)out_data, out_len) : newSVpvn(NULL, 0);
|
||||
Safefree(out_data);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
CryptX__decode_base64url(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN in_len;
|
||||
unsigned long out_len;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, in_len);
|
||||
out_len = (unsigned long)in_len;
|
||||
Newz(0, out_data, out_len, unsigned char);
|
||||
if (!out_data) croak("FATAL: Newz failed [%ld]", out_len);
|
||||
rv = base64url_decode(in_data, (unsigned long)in_len, out_data, &out_len);
|
||||
RETVAL = (rv == CRYPT_OK) ? newSVpvn((char *)out_data, out_len) : newSVpvn(NULL, 0);
|
||||
Safefree(out_data);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
CryptX__encode_base64(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN in_len;
|
||||
unsigned long out_len;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, in_len);
|
||||
out_len = (unsigned long)(4 * ((in_len + 2) / 3) + 1);
|
||||
Newz(0, out_data, out_len, unsigned char);
|
||||
if (!out_data) croak("FATAL: Newz failed [%ld]", out_len);
|
||||
rv = base64_encode(in_data, (unsigned long)in_len, out_data, &out_len);
|
||||
RETVAL = (rv == CRYPT_OK) ? newSVpvn((char *)out_data, out_len) : newSVpvn(NULL, 0);
|
||||
Safefree(out_data);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
CryptX__decode_base64(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN in_len;
|
||||
unsigned long out_len;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, in_len);
|
||||
out_len = (unsigned long)in_len;
|
||||
Newz(0, out_data, out_len, unsigned char);
|
||||
if (!out_data) croak("FATAL: Newz failed [%ld]", out_len);
|
||||
rv = base64_decode(in_data, (unsigned long)in_len, out_data, &out_len);
|
||||
RETVAL = (rv == CRYPT_OK) ? newSVpvn((char *)out_data, out_len) : newSVpvn(NULL, 0);
|
||||
Safefree(out_data);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
CryptX__increment_octets_le(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN len, i = 0;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, len);
|
||||
if (len == 0) XSRETURN_UNDEF;
|
||||
|
||||
RETVAL = NEWSV(0, len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
Copy(in_data, out_data, len, unsigned char);
|
||||
while (i < len) {
|
||||
out_data[i]++;
|
||||
if (0 != out_data[i]) break;
|
||||
i++;
|
||||
}
|
||||
if (i == len) croak("FATAL: increment_octets_le overflow");
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
CryptX__increment_octets_be(SV * in)
|
||||
CODE:
|
||||
{
|
||||
STRLEN len, i = 0;
|
||||
unsigned char *out_data, *in_data;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(in)) XSRETURN_UNDEF;
|
||||
in_data = (unsigned char *) SvPVbyte(in, len);
|
||||
if (len == 0) XSRETURN_UNDEF;
|
||||
|
||||
RETVAL = NEWSV(0, len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
Copy(in_data, out_data, len, unsigned char);
|
||||
while (i < len) {
|
||||
out_data[len - 1 - i]++;
|
||||
if (0 != out_data[len - 1 - i]) break;
|
||||
i++;
|
||||
}
|
||||
if (i == len) croak("FATAL: increment_octets_le overflow");
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
###############################################################################
|
||||
|
||||
INCLUDE: inc/CryptX_Digest.xs.inc
|
||||
INCLUDE: inc/CryptX_Digest_SHAKE.xs.inc
|
||||
INCLUDE: inc/CryptX_Cipher.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_Checksum_Adler32.xs.inc
|
||||
INCLUDE: inc/CryptX_Checksum_CRC32.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_AuthEnc_EAX.xs.inc
|
||||
INCLUDE: inc/CryptX_AuthEnc_GCM.xs.inc
|
||||
INCLUDE: inc/CryptX_AuthEnc_OCB.xs.inc
|
||||
INCLUDE: inc/CryptX_AuthEnc_CCM.xs.inc
|
||||
INCLUDE: inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_Stream_ChaCha.xs.inc
|
||||
INCLUDE: inc/CryptX_Stream_RC4.xs.inc
|
||||
INCLUDE: inc/CryptX_Stream_Sober128.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_Mac_F9.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_HMAC.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_OMAC.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_Pelican.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_PMAC.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_XCBC.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_Poly1305.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_BLAKE2s.xs.inc
|
||||
INCLUDE: inc/CryptX_Mac_BLAKE2b.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_Mode_CBC.xs.inc
|
||||
INCLUDE: inc/CryptX_Mode_ECB.xs.inc
|
||||
INCLUDE: inc/CryptX_Mode_CFB.xs.inc
|
||||
INCLUDE: inc/CryptX_Mode_OFB.xs.inc
|
||||
INCLUDE: inc/CryptX_Mode_CTR.xs.inc
|
||||
#INCLUDE: inc/CryptX_Mode_F8.xs.inc
|
||||
#INCLUDE: inc/CryptX_Mode_LRW.xs.inc
|
||||
#INCLUDE: inc/CryptX_Mode_XTS.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_PRNG.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_PK_RSA.xs.inc
|
||||
INCLUDE: inc/CryptX_PK_DSA.xs.inc
|
||||
INCLUDE: inc/CryptX_PK_DH.xs.inc
|
||||
INCLUDE: inc/CryptX_PK_ECC.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_KeyDerivation.xs.inc
|
||||
|
||||
INCLUDE: inc/CryptX_BigInt_LTM.xs.inc
|
1
LICENSE
Normal file
1
LICENSE
Normal file
@ -0,0 +1 @@
|
||||
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
929
MANIFEST
Normal file
929
MANIFEST
Normal file
@ -0,0 +1,929 @@
|
||||
Changes
|
||||
CryptX.xs
|
||||
inc/CryptX_AuthEnc_CCM.xs.inc
|
||||
inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc
|
||||
inc/CryptX_AuthEnc_EAX.xs.inc
|
||||
inc/CryptX_AuthEnc_GCM.xs.inc
|
||||
inc/CryptX_AuthEnc_OCB.xs.inc
|
||||
inc/CryptX_BigInt_LTM.xs.inc
|
||||
inc/CryptX_Checksum_Adler32.xs.inc
|
||||
inc/CryptX_Checksum_CRC32.xs.inc
|
||||
inc/CryptX_Cipher.xs.inc
|
||||
inc/CryptX_Digest.xs.inc
|
||||
inc/CryptX_Digest_SHAKE.xs.inc
|
||||
inc/CryptX_KeyDerivation.xs.inc
|
||||
inc/CryptX_Mac_BLAKE2b.xs.inc
|
||||
inc/CryptX_Mac_BLAKE2s.xs.inc
|
||||
inc/CryptX_Mac_F9.xs.inc
|
||||
inc/CryptX_Mac_HMAC.xs.inc
|
||||
inc/CryptX_Mac_OMAC.xs.inc
|
||||
inc/CryptX_Mac_Pelican.xs.inc
|
||||
inc/CryptX_Mac_PMAC.xs.inc
|
||||
inc/CryptX_Mac_Poly1305.xs.inc
|
||||
inc/CryptX_Mac_XCBC.xs.inc
|
||||
inc/CryptX_Mode_CBC.xs.inc
|
||||
inc/CryptX_Mode_CFB.xs.inc
|
||||
inc/CryptX_Mode_CTR.xs.inc
|
||||
inc/CryptX_Mode_ECB.xs.inc
|
||||
inc/CryptX_Mode_OFB.xs.inc
|
||||
inc/CryptX_PK_DH.xs.inc
|
||||
inc/CryptX_PK_DSA.xs.inc
|
||||
inc/CryptX_PK_ECC.xs.inc
|
||||
inc/CryptX_PK_RSA.xs.inc
|
||||
inc/CryptX_PRNG.xs.inc
|
||||
inc/CryptX_Stream_ChaCha.xs.inc
|
||||
inc/CryptX_Stream_RC4.xs.inc
|
||||
inc/CryptX_Stream_Sober128.xs.inc
|
||||
lib/Crypt/AuthEnc.pm
|
||||
lib/Crypt/AuthEnc/CCM.pm
|
||||
lib/Crypt/AuthEnc/ChaCha20Poly1305.pm
|
||||
lib/Crypt/AuthEnc/EAX.pm
|
||||
lib/Crypt/AuthEnc/GCM.pm
|
||||
lib/Crypt/AuthEnc/OCB.pm
|
||||
lib/Crypt/Checksum.pm
|
||||
lib/Crypt/Checksum/Adler32.pm
|
||||
lib/Crypt/Checksum/CRC32.pm
|
||||
lib/Crypt/Cipher.pm
|
||||
lib/Crypt/Cipher/AES.pm
|
||||
lib/Crypt/Cipher/Anubis.pm
|
||||
lib/Crypt/Cipher/Blowfish.pm
|
||||
lib/Crypt/Cipher/Camellia.pm
|
||||
lib/Crypt/Cipher/CAST5.pm
|
||||
lib/Crypt/Cipher/DES.pm
|
||||
lib/Crypt/Cipher/DES_EDE.pm
|
||||
lib/Crypt/Cipher/KASUMI.pm
|
||||
lib/Crypt/Cipher/Khazad.pm
|
||||
lib/Crypt/Cipher/MULTI2.pm
|
||||
lib/Crypt/Cipher/Noekeon.pm
|
||||
lib/Crypt/Cipher/RC2.pm
|
||||
lib/Crypt/Cipher/RC5.pm
|
||||
lib/Crypt/Cipher/RC6.pm
|
||||
lib/Crypt/Cipher/SAFER_K128.pm
|
||||
lib/Crypt/Cipher/SAFER_K64.pm
|
||||
lib/Crypt/Cipher/SAFER_SK128.pm
|
||||
lib/Crypt/Cipher/SAFER_SK64.pm
|
||||
lib/Crypt/Cipher/SAFERP.pm
|
||||
lib/Crypt/Cipher/SEED.pm
|
||||
lib/Crypt/Cipher/Skipjack.pm
|
||||
lib/Crypt/Cipher/Twofish.pm
|
||||
lib/Crypt/Cipher/XTEA.pm
|
||||
lib/Crypt/Digest.pm
|
||||
lib/Crypt/Digest/BLAKE2b_160.pm
|
||||
lib/Crypt/Digest/BLAKE2b_256.pm
|
||||
lib/Crypt/Digest/BLAKE2b_384.pm
|
||||
lib/Crypt/Digest/BLAKE2b_512.pm
|
||||
lib/Crypt/Digest/BLAKE2s_128.pm
|
||||
lib/Crypt/Digest/BLAKE2s_160.pm
|
||||
lib/Crypt/Digest/BLAKE2s_224.pm
|
||||
lib/Crypt/Digest/BLAKE2s_256.pm
|
||||
lib/Crypt/Digest/CHAES.pm
|
||||
lib/Crypt/Digest/MD2.pm
|
||||
lib/Crypt/Digest/MD4.pm
|
||||
lib/Crypt/Digest/MD5.pm
|
||||
lib/Crypt/Digest/RIPEMD128.pm
|
||||
lib/Crypt/Digest/RIPEMD160.pm
|
||||
lib/Crypt/Digest/RIPEMD256.pm
|
||||
lib/Crypt/Digest/RIPEMD320.pm
|
||||
lib/Crypt/Digest/SHA1.pm
|
||||
lib/Crypt/Digest/SHA224.pm
|
||||
lib/Crypt/Digest/SHA256.pm
|
||||
lib/Crypt/Digest/SHA384.pm
|
||||
lib/Crypt/Digest/SHA3_224.pm
|
||||
lib/Crypt/Digest/SHA3_256.pm
|
||||
lib/Crypt/Digest/SHA3_384.pm
|
||||
lib/Crypt/Digest/SHA3_512.pm
|
||||
lib/Crypt/Digest/SHA512.pm
|
||||
lib/Crypt/Digest/SHA512_224.pm
|
||||
lib/Crypt/Digest/SHA512_256.pm
|
||||
lib/Crypt/Digest/SHAKE.pm
|
||||
lib/Crypt/Digest/Tiger192.pm
|
||||
lib/Crypt/Digest/Whirlpool.pm
|
||||
lib/Crypt/KeyDerivation.pm
|
||||
lib/Crypt/Mac.pm
|
||||
lib/Crypt/Mac/BLAKE2b.pm
|
||||
lib/Crypt/Mac/BLAKE2s.pm
|
||||
lib/Crypt/Mac/F9.pm
|
||||
lib/Crypt/Mac/HMAC.pm
|
||||
lib/Crypt/Mac/OMAC.pm
|
||||
lib/Crypt/Mac/Pelican.pm
|
||||
lib/Crypt/Mac/PMAC.pm
|
||||
lib/Crypt/Mac/Poly1305.pm
|
||||
lib/Crypt/Mac/XCBC.pm
|
||||
lib/Crypt/Misc.pm
|
||||
lib/Crypt/Mode.pm
|
||||
lib/Crypt/Mode/CBC.pm
|
||||
lib/Crypt/Mode/CFB.pm
|
||||
lib/Crypt/Mode/CTR.pm
|
||||
lib/Crypt/Mode/ECB.pm
|
||||
lib/Crypt/Mode/OFB.pm
|
||||
lib/Crypt/PK.pm
|
||||
lib/Crypt/PK/DH.pm
|
||||
lib/Crypt/PK/DSA.pm
|
||||
lib/Crypt/PK/ECC.pm
|
||||
lib/Crypt/PK/RSA.pm
|
||||
lib/Crypt/PRNG.pm
|
||||
lib/Crypt/PRNG/ChaCha20.pm
|
||||
lib/Crypt/PRNG/Fortuna.pm
|
||||
lib/Crypt/PRNG/RC4.pm
|
||||
lib/Crypt/PRNG/Sober128.pm
|
||||
lib/Crypt/PRNG/Yarrow.pm
|
||||
lib/Crypt/Stream/ChaCha.pm
|
||||
lib/Crypt/Stream/RC4.pm
|
||||
lib/Crypt/Stream/Sober128.pm
|
||||
lib/CryptX.pm
|
||||
lib/Math/BigInt/LTM.pm
|
||||
LICENSE
|
||||
Makefile.PL
|
||||
MANIFEST This list of files
|
||||
META.json
|
||||
META.yml
|
||||
ppport.h
|
||||
README
|
||||
src/ltc/ciphers/aes/aes.c
|
||||
src/ltc/ciphers/aes/aes_tab.c
|
||||
src/ltc/ciphers/anubis.c
|
||||
src/ltc/ciphers/blowfish.c
|
||||
src/ltc/ciphers/camellia.c
|
||||
src/ltc/ciphers/cast5.c
|
||||
src/ltc/ciphers/des.c
|
||||
src/ltc/ciphers/kasumi.c
|
||||
src/ltc/ciphers/khazad.c
|
||||
src/ltc/ciphers/kseed.c
|
||||
src/ltc/ciphers/multi2.c
|
||||
src/ltc/ciphers/noekeon.c
|
||||
src/ltc/ciphers/rc2.c
|
||||
src/ltc/ciphers/rc5.c
|
||||
src/ltc/ciphers/rc6.c
|
||||
src/ltc/ciphers/safer/safer.c
|
||||
src/ltc/ciphers/safer/safer_tab.c
|
||||
src/ltc/ciphers/safer/saferp.c
|
||||
src/ltc/ciphers/skipjack.c
|
||||
src/ltc/ciphers/twofish/twofish.c
|
||||
src/ltc/ciphers/twofish/twofish_tab.c
|
||||
src/ltc/ciphers/xtea.c
|
||||
src/ltc/encauth/ccm/ccm_add_aad.c
|
||||
src/ltc/encauth/ccm/ccm_add_nonce.c
|
||||
src/ltc/encauth/ccm/ccm_done.c
|
||||
src/ltc/encauth/ccm/ccm_init.c
|
||||
src/ltc/encauth/ccm/ccm_memory.c
|
||||
src/ltc/encauth/ccm/ccm_process.c
|
||||
src/ltc/encauth/ccm/ccm_reset.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_add_aad.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_decrypt.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_done.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_encrypt.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_init.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_memory.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_setiv.c
|
||||
src/ltc/encauth/chachapoly/chacha20poly1305_setiv_rfc7905.c
|
||||
src/ltc/encauth/eax/eax_addheader.c
|
||||
src/ltc/encauth/eax/eax_decrypt.c
|
||||
src/ltc/encauth/eax/eax_decrypt_verify_memory.c
|
||||
src/ltc/encauth/eax/eax_done.c
|
||||
src/ltc/encauth/eax/eax_encrypt.c
|
||||
src/ltc/encauth/eax/eax_encrypt_authenticate_memory.c
|
||||
src/ltc/encauth/eax/eax_init.c
|
||||
src/ltc/encauth/gcm/gcm_add_aad.c
|
||||
src/ltc/encauth/gcm/gcm_add_iv.c
|
||||
src/ltc/encauth/gcm/gcm_done.c
|
||||
src/ltc/encauth/gcm/gcm_gf_mult.c
|
||||
src/ltc/encauth/gcm/gcm_init.c
|
||||
src/ltc/encauth/gcm/gcm_memory.c
|
||||
src/ltc/encauth/gcm/gcm_mult_h.c
|
||||
src/ltc/encauth/gcm/gcm_process.c
|
||||
src/ltc/encauth/gcm/gcm_reset.c
|
||||
src/ltc/encauth/ocb3/ocb3_add_aad.c
|
||||
src/ltc/encauth/ocb3/ocb3_decrypt.c
|
||||
src/ltc/encauth/ocb3/ocb3_decrypt_last.c
|
||||
src/ltc/encauth/ocb3/ocb3_decrypt_verify_memory.c
|
||||
src/ltc/encauth/ocb3/ocb3_done.c
|
||||
src/ltc/encauth/ocb3/ocb3_encrypt.c
|
||||
src/ltc/encauth/ocb3/ocb3_encrypt_authenticate_memory.c
|
||||
src/ltc/encauth/ocb3/ocb3_encrypt_last.c
|
||||
src/ltc/encauth/ocb3/ocb3_init.c
|
||||
src/ltc/encauth/ocb3/ocb3_int_aad_add_block.c
|
||||
src/ltc/encauth/ocb3/ocb3_int_calc_offset_zero.c
|
||||
src/ltc/encauth/ocb3/ocb3_int_ntz.c
|
||||
src/ltc/encauth/ocb3/ocb3_int_xor_blocks.c
|
||||
src/ltc/hashes/blake2b.c
|
||||
src/ltc/hashes/blake2s.c
|
||||
src/ltc/hashes/chc/chc.c
|
||||
src/ltc/hashes/helper/hash_file.c
|
||||
src/ltc/hashes/helper/hash_filehandle.c
|
||||
src/ltc/hashes/helper/hash_memory.c
|
||||
src/ltc/hashes/helper/hash_memory_multi.c
|
||||
src/ltc/hashes/md2.c
|
||||
src/ltc/hashes/md4.c
|
||||
src/ltc/hashes/md5.c
|
||||
src/ltc/hashes/rmd128.c
|
||||
src/ltc/hashes/rmd160.c
|
||||
src/ltc/hashes/rmd256.c
|
||||
src/ltc/hashes/rmd320.c
|
||||
src/ltc/hashes/sha1.c
|
||||
src/ltc/hashes/sha2/sha224.c
|
||||
src/ltc/hashes/sha2/sha256.c
|
||||
src/ltc/hashes/sha2/sha384.c
|
||||
src/ltc/hashes/sha2/sha512.c
|
||||
src/ltc/hashes/sha2/sha512_224.c
|
||||
src/ltc/hashes/sha2/sha512_256.c
|
||||
src/ltc/hashes/sha3.c
|
||||
src/ltc/hashes/sha3_test.c
|
||||
src/ltc/hashes/tiger.c
|
||||
src/ltc/hashes/whirl/whirl.c
|
||||
src/ltc/hashes/whirl/whirltab.c
|
||||
src/ltc/headers/tomcrypt.h
|
||||
src/ltc/headers/tomcrypt_argchk.h
|
||||
src/ltc/headers/tomcrypt_cfg.h
|
||||
src/ltc/headers/tomcrypt_cipher.h
|
||||
src/ltc/headers/tomcrypt_custom.h
|
||||
src/ltc/headers/tomcrypt_hash.h
|
||||
src/ltc/headers/tomcrypt_mac.h
|
||||
src/ltc/headers/tomcrypt_macros.h
|
||||
src/ltc/headers/tomcrypt_math.h
|
||||
src/ltc/headers/tomcrypt_misc.h
|
||||
src/ltc/headers/tomcrypt_pk.h
|
||||
src/ltc/headers/tomcrypt_pkcs.h
|
||||
src/ltc/headers/tomcrypt_prng.h
|
||||
src/ltc/mac/blake2/blake2bmac.c
|
||||
src/ltc/mac/blake2/blake2bmac_file.c
|
||||
src/ltc/mac/blake2/blake2bmac_memory.c
|
||||
src/ltc/mac/blake2/blake2bmac_memory_multi.c
|
||||
src/ltc/mac/blake2/blake2smac.c
|
||||
src/ltc/mac/blake2/blake2smac_file.c
|
||||
src/ltc/mac/blake2/blake2smac_memory.c
|
||||
src/ltc/mac/blake2/blake2smac_memory_multi.c
|
||||
src/ltc/mac/f9/f9_done.c
|
||||
src/ltc/mac/f9/f9_file.c
|
||||
src/ltc/mac/f9/f9_init.c
|
||||
src/ltc/mac/f9/f9_memory.c
|
||||
src/ltc/mac/f9/f9_memory_multi.c
|
||||
src/ltc/mac/f9/f9_process.c
|
||||
src/ltc/mac/hmac/hmac_done.c
|
||||
src/ltc/mac/hmac/hmac_file.c
|
||||
src/ltc/mac/hmac/hmac_init.c
|
||||
src/ltc/mac/hmac/hmac_memory.c
|
||||
src/ltc/mac/hmac/hmac_memory_multi.c
|
||||
src/ltc/mac/hmac/hmac_process.c
|
||||
src/ltc/mac/omac/omac_done.c
|
||||
src/ltc/mac/omac/omac_file.c
|
||||
src/ltc/mac/omac/omac_init.c
|
||||
src/ltc/mac/omac/omac_memory.c
|
||||
src/ltc/mac/omac/omac_memory_multi.c
|
||||
src/ltc/mac/omac/omac_process.c
|
||||
src/ltc/mac/pelican/pelican.c
|
||||
src/ltc/mac/pelican/pelican_memory.c
|
||||
src/ltc/mac/pmac/pmac_done.c
|
||||
src/ltc/mac/pmac/pmac_file.c
|
||||
src/ltc/mac/pmac/pmac_init.c
|
||||
src/ltc/mac/pmac/pmac_memory.c
|
||||
src/ltc/mac/pmac/pmac_memory_multi.c
|
||||
src/ltc/mac/pmac/pmac_ntz.c
|
||||
src/ltc/mac/pmac/pmac_process.c
|
||||
src/ltc/mac/pmac/pmac_shift_xor.c
|
||||
src/ltc/mac/poly1305/poly1305.c
|
||||
src/ltc/mac/poly1305/poly1305_file.c
|
||||
src/ltc/mac/poly1305/poly1305_memory.c
|
||||
src/ltc/mac/poly1305/poly1305_memory_multi.c
|
||||
src/ltc/mac/xcbc/xcbc_done.c
|
||||
src/ltc/mac/xcbc/xcbc_file.c
|
||||
src/ltc/mac/xcbc/xcbc_init.c
|
||||
src/ltc/mac/xcbc/xcbc_memory.c
|
||||
src/ltc/mac/xcbc/xcbc_memory_multi.c
|
||||
src/ltc/mac/xcbc/xcbc_process.c
|
||||
src/ltc/math/fp/ltc_ecc_fp_mulmod.c
|
||||
src/ltc/math/ltm_desc.c
|
||||
src/ltc/math/multi.c
|
||||
src/ltc/math/rand_bn.c
|
||||
src/ltc/math/rand_prime.c
|
||||
src/ltc/math/tfm_desc.c
|
||||
src/ltc/misc/adler32.c
|
||||
src/ltc/misc/base64/base64_decode.c
|
||||
src/ltc/misc/base64/base64_encode.c
|
||||
src/ltc/misc/burn_stack.c
|
||||
src/ltc/misc/crc32.c
|
||||
src/ltc/misc/crypt/crypt.c
|
||||
src/ltc/misc/crypt/crypt_argchk.c
|
||||
src/ltc/misc/crypt/crypt_cipher_descriptor.c
|
||||
src/ltc/misc/crypt/crypt_cipher_is_valid.c
|
||||
src/ltc/misc/crypt/crypt_find_cipher.c
|
||||
src/ltc/misc/crypt/crypt_find_cipher_any.c
|
||||
src/ltc/misc/crypt/crypt_find_cipher_id.c
|
||||
src/ltc/misc/crypt/crypt_find_hash.c
|
||||
src/ltc/misc/crypt/crypt_find_hash_any.c
|
||||
src/ltc/misc/crypt/crypt_find_hash_id.c
|
||||
src/ltc/misc/crypt/crypt_find_hash_oid.c
|
||||
src/ltc/misc/crypt/crypt_find_prng.c
|
||||
src/ltc/misc/crypt/crypt_fsa.c
|
||||
src/ltc/misc/crypt/crypt_hash_descriptor.c
|
||||
src/ltc/misc/crypt/crypt_hash_is_valid.c
|
||||
src/ltc/misc/crypt/crypt_inits.c
|
||||
src/ltc/misc/crypt/crypt_ltc_mp_descriptor.c
|
||||
src/ltc/misc/crypt/crypt_prng_descriptor.c
|
||||
src/ltc/misc/crypt/crypt_prng_is_valid.c
|
||||
src/ltc/misc/crypt/crypt_register_cipher.c
|
||||
src/ltc/misc/crypt/crypt_register_hash.c
|
||||
src/ltc/misc/crypt/crypt_register_prng.c
|
||||
src/ltc/misc/crypt/crypt_unregister_cipher.c
|
||||
src/ltc/misc/crypt/crypt_unregister_hash.c
|
||||
src/ltc/misc/crypt/crypt_unregister_prng.c
|
||||
src/ltc/misc/error_to_string.c
|
||||
src/ltc/misc/hkdf/hkdf.c
|
||||
src/ltc/misc/mem_neq.c
|
||||
src/ltc/misc/pk_get_oid.c
|
||||
src/ltc/misc/pkcs5/pkcs_5_1.c
|
||||
src/ltc/misc/pkcs5/pkcs_5_2.c
|
||||
src/ltc/misc/zeromem.c
|
||||
src/ltc/modes/cbc/cbc_decrypt.c
|
||||
src/ltc/modes/cbc/cbc_done.c
|
||||
src/ltc/modes/cbc/cbc_encrypt.c
|
||||
src/ltc/modes/cbc/cbc_getiv.c
|
||||
src/ltc/modes/cbc/cbc_setiv.c
|
||||
src/ltc/modes/cbc/cbc_start.c
|
||||
src/ltc/modes/cfb/cfb_decrypt.c
|
||||
src/ltc/modes/cfb/cfb_done.c
|
||||
src/ltc/modes/cfb/cfb_encrypt.c
|
||||
src/ltc/modes/cfb/cfb_getiv.c
|
||||
src/ltc/modes/cfb/cfb_setiv.c
|
||||
src/ltc/modes/cfb/cfb_start.c
|
||||
src/ltc/modes/ctr/ctr_decrypt.c
|
||||
src/ltc/modes/ctr/ctr_done.c
|
||||
src/ltc/modes/ctr/ctr_encrypt.c
|
||||
src/ltc/modes/ctr/ctr_getiv.c
|
||||
src/ltc/modes/ctr/ctr_setiv.c
|
||||
src/ltc/modes/ctr/ctr_start.c
|
||||
src/ltc/modes/ecb/ecb_decrypt.c
|
||||
src/ltc/modes/ecb/ecb_done.c
|
||||
src/ltc/modes/ecb/ecb_encrypt.c
|
||||
src/ltc/modes/ecb/ecb_start.c
|
||||
src/ltc/modes/ofb/ofb_decrypt.c
|
||||
src/ltc/modes/ofb/ofb_done.c
|
||||
src/ltc/modes/ofb/ofb_encrypt.c
|
||||
src/ltc/modes/ofb/ofb_getiv.c
|
||||
src/ltc/modes/ofb/ofb_setiv.c
|
||||
src/ltc/modes/ofb/ofb_start.c
|
||||
src/ltc/pk/asn1/der/bit/der_decode_bit_string.c
|
||||
src/ltc/pk/asn1/der/bit/der_decode_raw_bit_string.c
|
||||
src/ltc/pk/asn1/der/bit/der_encode_bit_string.c
|
||||
src/ltc/pk/asn1/der/bit/der_encode_raw_bit_string.c
|
||||
src/ltc/pk/asn1/der/bit/der_length_bit_string.c
|
||||
src/ltc/pk/asn1/der/boolean/der_decode_boolean.c
|
||||
src/ltc/pk/asn1/der/boolean/der_encode_boolean.c
|
||||
src/ltc/pk/asn1/der/boolean/der_length_boolean.c
|
||||
src/ltc/pk/asn1/der/choice/der_decode_choice.c
|
||||
src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
|
||||
src/ltc/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c
|
||||
src/ltc/pk/asn1/der/generalizedtime/der_length_generalizedtime.c
|
||||
src/ltc/pk/asn1/der/ia5/der_decode_ia5_string.c
|
||||
src/ltc/pk/asn1/der/ia5/der_encode_ia5_string.c
|
||||
src/ltc/pk/asn1/der/ia5/der_length_ia5_string.c
|
||||
src/ltc/pk/asn1/der/integer/der_decode_integer.c
|
||||
src/ltc/pk/asn1/der/integer/der_encode_integer.c
|
||||
src/ltc/pk/asn1/der/integer/der_length_integer.c
|
||||
src/ltc/pk/asn1/der/object_identifier/der_decode_object_identifier.c
|
||||
src/ltc/pk/asn1/der/object_identifier/der_encode_object_identifier.c
|
||||
src/ltc/pk/asn1/der/object_identifier/der_length_object_identifier.c
|
||||
src/ltc/pk/asn1/der/octet/der_decode_octet_string.c
|
||||
src/ltc/pk/asn1/der/octet/der_encode_octet_string.c
|
||||
src/ltc/pk/asn1/der/octet/der_length_octet_string.c
|
||||
src/ltc/pk/asn1/der/printable_string/der_decode_printable_string.c
|
||||
src/ltc/pk/asn1/der/printable_string/der_encode_printable_string.c
|
||||
src/ltc/pk/asn1/der/printable_string/der_length_printable_string.c
|
||||
src/ltc/pk/asn1/der/sequence/der_decode_sequence_ex.c
|
||||
src/ltc/pk/asn1/der/sequence/der_decode_sequence_flexi.c
|
||||
src/ltc/pk/asn1/der/sequence/der_decode_sequence_multi.c
|
||||
src/ltc/pk/asn1/der/sequence/der_decode_subject_public_key_info.c
|
||||
src/ltc/pk/asn1/der/sequence/der_encode_sequence_ex.c
|
||||
src/ltc/pk/asn1/der/sequence/der_encode_sequence_multi.c
|
||||
src/ltc/pk/asn1/der/sequence/der_encode_subject_public_key_info.c
|
||||
src/ltc/pk/asn1/der/sequence/der_length_sequence.c
|
||||
src/ltc/pk/asn1/der/sequence/der_sequence_free.c
|
||||
src/ltc/pk/asn1/der/set/der_encode_set.c
|
||||
src/ltc/pk/asn1/der/set/der_encode_setof.c
|
||||
src/ltc/pk/asn1/der/short_integer/der_decode_short_integer.c
|
||||
src/ltc/pk/asn1/der/short_integer/der_encode_short_integer.c
|
||||
src/ltc/pk/asn1/der/short_integer/der_length_short_integer.c
|
||||
src/ltc/pk/asn1/der/teletex_string/der_decode_teletex_string.c
|
||||
src/ltc/pk/asn1/der/teletex_string/der_length_teletex_string.c
|
||||
src/ltc/pk/asn1/der/utctime/der_decode_utctime.c
|
||||
src/ltc/pk/asn1/der/utctime/der_encode_utctime.c
|
||||
src/ltc/pk/asn1/der/utctime/der_length_utctime.c
|
||||
src/ltc/pk/asn1/der/utf8/der_decode_utf8_string.c
|
||||
src/ltc/pk/asn1/der/utf8/der_encode_utf8_string.c
|
||||
src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c
|
||||
src/ltc/pk/dh/dh.c
|
||||
src/ltc/pk/dh/dh_static.c
|
||||
src/ltc/pk/dh/dh_static.h
|
||||
src/ltc/pk/dh/dh_sys.c
|
||||
src/ltc/pk/dsa/dsa_decrypt_key.c
|
||||
src/ltc/pk/dsa/dsa_encrypt_key.c
|
||||
src/ltc/pk/dsa/dsa_export.c
|
||||
src/ltc/pk/dsa/dsa_free.c
|
||||
src/ltc/pk/dsa/dsa_import.c
|
||||
src/ltc/pk/dsa/dsa_import_radix.c
|
||||
src/ltc/pk/dsa/dsa_make_key.c
|
||||
src/ltc/pk/dsa/dsa_shared_secret.c
|
||||
src/ltc/pk/dsa/dsa_sign_hash.c
|
||||
src/ltc/pk/dsa/dsa_verify_hash.c
|
||||
src/ltc/pk/dsa/dsa_verify_key.c
|
||||
src/ltc/pk/ecc/ecc.c
|
||||
src/ltc/pk/ecc/ecc_ansi_x963_export.c
|
||||
src/ltc/pk/ecc/ecc_ansi_x963_import.c
|
||||
src/ltc/pk/ecc/ecc_decrypt_key.c
|
||||
src/ltc/pk/ecc/ecc_dp_clear.c
|
||||
src/ltc/pk/ecc/ecc_dp_fill_from_sets.c
|
||||
src/ltc/pk/ecc/ecc_dp_from_oid.c
|
||||
src/ltc/pk/ecc/ecc_dp_from_params.c
|
||||
src/ltc/pk/ecc/ecc_dp_init.c
|
||||
src/ltc/pk/ecc/ecc_dp_set.c
|
||||
src/ltc/pk/ecc/ecc_encrypt_key.c
|
||||
src/ltc/pk/ecc/ecc_export.c
|
||||
src/ltc/pk/ecc/ecc_export_full.c
|
||||
src/ltc/pk/ecc/ecc_export_raw.c
|
||||
src/ltc/pk/ecc/ecc_free.c
|
||||
src/ltc/pk/ecc/ecc_get_size.c
|
||||
src/ltc/pk/ecc/ecc_import.c
|
||||
src/ltc/pk/ecc/ecc_import_full.c
|
||||
src/ltc/pk/ecc/ecc_import_pkcs8.c
|
||||
src/ltc/pk/ecc/ecc_import_raw.c
|
||||
src/ltc/pk/ecc/ecc_make_key.c
|
||||
src/ltc/pk/ecc/ecc_shared_secret.c
|
||||
src/ltc/pk/ecc/ecc_sign_hash.c
|
||||
src/ltc/pk/ecc/ecc_sizes.c
|
||||
src/ltc/pk/ecc/ecc_verify_hash.c
|
||||
src/ltc/pk/ecc/ecc_verify_key.c
|
||||
src/ltc/pk/ecc/ltc_ecc_export_point.c
|
||||
src/ltc/pk/ecc/ltc_ecc_import_point.c
|
||||
src/ltc/pk/ecc/ltc_ecc_is_point.c
|
||||
src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c
|
||||
src/ltc/pk/ecc/ltc_ecc_is_valid_idx.c
|
||||
src/ltc/pk/ecc/ltc_ecc_map.c
|
||||
src/ltc/pk/ecc/ltc_ecc_mul2add.c
|
||||
src/ltc/pk/ecc/ltc_ecc_mulmod.c
|
||||
src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c
|
||||
src/ltc/pk/ecc/ltc_ecc_points.c
|
||||
src/ltc/pk/ecc/ltc_ecc_projective_add_point.c
|
||||
src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_i2osp.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_mgf1.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_oaep_decode.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_oaep_encode.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_os2ip.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_pss_decode.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_pss_encode.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_v1_5_decode.c
|
||||
src/ltc/pk/pkcs1/pkcs_1_v1_5_encode.c
|
||||
src/ltc/pk/rsa/rsa_decrypt_key.c
|
||||
src/ltc/pk/rsa/rsa_encrypt_key.c
|
||||
src/ltc/pk/rsa/rsa_export.c
|
||||
src/ltc/pk/rsa/rsa_exptmod.c
|
||||
src/ltc/pk/rsa/rsa_free.c
|
||||
src/ltc/pk/rsa/rsa_get_size.c
|
||||
src/ltc/pk/rsa/rsa_import.c
|
||||
src/ltc/pk/rsa/rsa_import_pkcs8.c
|
||||
src/ltc/pk/rsa/rsa_import_radix.c
|
||||
src/ltc/pk/rsa/rsa_import_x509.c
|
||||
src/ltc/pk/rsa/rsa_make_key.c
|
||||
src/ltc/pk/rsa/rsa_sign_hash.c
|
||||
src/ltc/pk/rsa/rsa_sign_saltlen_get.c
|
||||
src/ltc/pk/rsa/rsa_verify_hash.c
|
||||
src/ltc/prngs/chacha20.c
|
||||
src/ltc/prngs/fortuna.c
|
||||
src/ltc/prngs/rc4.c
|
||||
src/ltc/prngs/rng_get_bytes.c
|
||||
src/ltc/prngs/rng_make_prng.c
|
||||
src/ltc/prngs/sober128.c
|
||||
src/ltc/prngs/sprng.c
|
||||
src/ltc/prngs/yarrow.c
|
||||
src/ltc/stream/chacha/chacha_crypt.c
|
||||
src/ltc/stream/chacha/chacha_done.c
|
||||
src/ltc/stream/chacha/chacha_ivctr32.c
|
||||
src/ltc/stream/chacha/chacha_ivctr64.c
|
||||
src/ltc/stream/chacha/chacha_keystream.c
|
||||
src/ltc/stream/chacha/chacha_setup.c
|
||||
src/ltc/stream/rc4/rc4.c
|
||||
src/ltc/stream/sober128/sober128.c
|
||||
src/ltc/stream/sober128/sober128tab.c
|
||||
src/ltm/bn_error.c
|
||||
src/ltm/bn_fast_mp_invmod.c
|
||||
src/ltm/bn_fast_mp_montgomery_reduce.c
|
||||
src/ltm/bn_fast_s_mp_mul_digs.c
|
||||
src/ltm/bn_fast_s_mp_mul_high_digs.c
|
||||
src/ltm/bn_fast_s_mp_sqr.c
|
||||
src/ltm/bn_mp_2expt.c
|
||||
src/ltm/bn_mp_abs.c
|
||||
src/ltm/bn_mp_add.c
|
||||
src/ltm/bn_mp_add_d.c
|
||||
src/ltm/bn_mp_addmod.c
|
||||
src/ltm/bn_mp_and.c
|
||||
src/ltm/bn_mp_clamp.c
|
||||
src/ltm/bn_mp_clear.c
|
||||
src/ltm/bn_mp_clear_multi.c
|
||||
src/ltm/bn_mp_cmp.c
|
||||
src/ltm/bn_mp_cmp_d.c
|
||||
src/ltm/bn_mp_cmp_mag.c
|
||||
src/ltm/bn_mp_cnt_lsb.c
|
||||
src/ltm/bn_mp_copy.c
|
||||
src/ltm/bn_mp_count_bits.c
|
||||
src/ltm/bn_mp_div.c
|
||||
src/ltm/bn_mp_div_2.c
|
||||
src/ltm/bn_mp_div_2d.c
|
||||
src/ltm/bn_mp_div_3.c
|
||||
src/ltm/bn_mp_div_d.c
|
||||
src/ltm/bn_mp_dr_is_modulus.c
|
||||
src/ltm/bn_mp_dr_reduce.c
|
||||
src/ltm/bn_mp_dr_setup.c
|
||||
src/ltm/bn_mp_exch.c
|
||||
src/ltm/bn_mp_export.c
|
||||
src/ltm/bn_mp_expt_d.c
|
||||
src/ltm/bn_mp_expt_d_ex.c
|
||||
src/ltm/bn_mp_exptmod.c
|
||||
src/ltm/bn_mp_exptmod_fast.c
|
||||
src/ltm/bn_mp_exteuclid.c
|
||||
src/ltm/bn_mp_fread.c
|
||||
src/ltm/bn_mp_fwrite.c
|
||||
src/ltm/bn_mp_gcd.c
|
||||
src/ltm/bn_mp_get_int.c
|
||||
src/ltm/bn_mp_get_long.c
|
||||
src/ltm/bn_mp_get_long_long.c
|
||||
src/ltm/bn_mp_grow.c
|
||||
src/ltm/bn_mp_import.c
|
||||
src/ltm/bn_mp_init.c
|
||||
src/ltm/bn_mp_init_copy.c
|
||||
src/ltm/bn_mp_init_multi.c
|
||||
src/ltm/bn_mp_init_set.c
|
||||
src/ltm/bn_mp_init_set_int.c
|
||||
src/ltm/bn_mp_init_size.c
|
||||
src/ltm/bn_mp_invmod.c
|
||||
src/ltm/bn_mp_invmod_slow.c
|
||||
src/ltm/bn_mp_is_square.c
|
||||
src/ltm/bn_mp_jacobi.c
|
||||
src/ltm/bn_mp_karatsuba_mul.c
|
||||
src/ltm/bn_mp_karatsuba_sqr.c
|
||||
src/ltm/bn_mp_lcm.c
|
||||
src/ltm/bn_mp_lshd.c
|
||||
src/ltm/bn_mp_mod.c
|
||||
src/ltm/bn_mp_mod_2d.c
|
||||
src/ltm/bn_mp_mod_d.c
|
||||
src/ltm/bn_mp_montgomery_calc_normalization.c
|
||||
src/ltm/bn_mp_montgomery_reduce.c
|
||||
src/ltm/bn_mp_montgomery_setup.c
|
||||
src/ltm/bn_mp_mul.c
|
||||
src/ltm/bn_mp_mul_2.c
|
||||
src/ltm/bn_mp_mul_2d.c
|
||||
src/ltm/bn_mp_mul_d.c
|
||||
src/ltm/bn_mp_mulmod.c
|
||||
src/ltm/bn_mp_n_root.c
|
||||
src/ltm/bn_mp_n_root_ex.c
|
||||
src/ltm/bn_mp_neg.c
|
||||
src/ltm/bn_mp_or.c
|
||||
src/ltm/bn_mp_prime_fermat.c
|
||||
src/ltm/bn_mp_prime_is_divisible.c
|
||||
src/ltm/bn_mp_prime_is_prime.c
|
||||
src/ltm/bn_mp_prime_miller_rabin.c
|
||||
src/ltm/bn_mp_prime_next_prime.c
|
||||
src/ltm/bn_mp_prime_rabin_miller_trials.c
|
||||
src/ltm/bn_mp_prime_random_ex.c
|
||||
src/ltm/bn_mp_radix_size.c
|
||||
src/ltm/bn_mp_radix_smap.c
|
||||
src/ltm/bn_mp_rand.c
|
||||
src/ltm/bn_mp_read_radix.c
|
||||
src/ltm/bn_mp_read_signed_bin.c
|
||||
src/ltm/bn_mp_read_unsigned_bin.c
|
||||
src/ltm/bn_mp_reduce.c
|
||||
src/ltm/bn_mp_reduce_2k.c
|
||||
src/ltm/bn_mp_reduce_2k_l.c
|
||||
src/ltm/bn_mp_reduce_2k_setup.c
|
||||
src/ltm/bn_mp_reduce_2k_setup_l.c
|
||||
src/ltm/bn_mp_reduce_is_2k.c
|
||||
src/ltm/bn_mp_reduce_is_2k_l.c
|
||||
src/ltm/bn_mp_reduce_setup.c
|
||||
src/ltm/bn_mp_rshd.c
|
||||
src/ltm/bn_mp_set.c
|
||||
src/ltm/bn_mp_set_int.c
|
||||
src/ltm/bn_mp_set_long.c
|
||||
src/ltm/bn_mp_set_long_long.c
|
||||
src/ltm/bn_mp_shrink.c
|
||||
src/ltm/bn_mp_signed_bin_size.c
|
||||
src/ltm/bn_mp_sqr.c
|
||||
src/ltm/bn_mp_sqrmod.c
|
||||
src/ltm/bn_mp_sqrt.c
|
||||
src/ltm/bn_mp_sqrtmod_prime.c
|
||||
src/ltm/bn_mp_sub.c
|
||||
src/ltm/bn_mp_sub_d.c
|
||||
src/ltm/bn_mp_submod.c
|
||||
src/ltm/bn_mp_to_signed_bin.c
|
||||
src/ltm/bn_mp_to_signed_bin_n.c
|
||||
src/ltm/bn_mp_to_unsigned_bin.c
|
||||
src/ltm/bn_mp_to_unsigned_bin_n.c
|
||||
src/ltm/bn_mp_toom_mul.c
|
||||
src/ltm/bn_mp_toom_sqr.c
|
||||
src/ltm/bn_mp_toradix.c
|
||||
src/ltm/bn_mp_toradix_n.c
|
||||
src/ltm/bn_mp_unsigned_bin_size.c
|
||||
src/ltm/bn_mp_xor.c
|
||||
src/ltm/bn_mp_zero.c
|
||||
src/ltm/bn_prime_tab.c
|
||||
src/ltm/bn_reverse.c
|
||||
src/ltm/bn_s_mp_add.c
|
||||
src/ltm/bn_s_mp_exptmod.c
|
||||
src/ltm/bn_s_mp_mul_digs.c
|
||||
src/ltm/bn_s_mp_mul_high_digs.c
|
||||
src/ltm/bn_s_mp_sqr.c
|
||||
src/ltm/bn_s_mp_sub.c
|
||||
src/ltm/bncore.c
|
||||
src/ltm/tommath.h
|
||||
src/ltm/tommath_class.h
|
||||
src/ltm/tommath_private.h
|
||||
src/ltm/tommath_superclass.h
|
||||
src/Makefile
|
||||
src/Makefile.nmake
|
||||
t/001_compile.t
|
||||
t/002_all_pm.t
|
||||
t/003_all_pm_pod.t
|
||||
t/auth_enc_ccm.t
|
||||
t/auth_enc_ccm_test_vector_ltc.t
|
||||
t/auth_enc_chacha20poly1305.t
|
||||
t/auth_enc_eax.t
|
||||
t/auth_enc_eax_test_vector_ltc.t
|
||||
t/auth_enc_gcm.t
|
||||
t/auth_enc_gcm_test_vector_ltc.t
|
||||
t/auth_enc_ocb.t
|
||||
t/auth_enc_ocb_test_vectors_ietf.t
|
||||
t/checksum.t
|
||||
t/cipher_aes.t
|
||||
t/cipher_aes_test_vectors_bc.t
|
||||
t/cipher_anubis.t
|
||||
t/cipher_blowfish.t
|
||||
t/cipher_camellia.t
|
||||
t/cipher_cast5.t
|
||||
t/cipher_des.t
|
||||
t/cipher_des_ede.t
|
||||
t/cipher_kasumi.t
|
||||
t/cipher_khazad.t
|
||||
t/cipher_multi2.t
|
||||
t/cipher_multi2_rounds.t
|
||||
t/cipher_noekeon.t
|
||||
t/cipher_rc2.t
|
||||
t/cipher_rc5.t
|
||||
t/cipher_rc6.t
|
||||
t/cipher_safer_k128.t
|
||||
t/cipher_safer_k64.t
|
||||
t/cipher_safer_sk128.t
|
||||
t/cipher_safer_sk64.t
|
||||
t/cipher_saferp.t
|
||||
t/cipher_seed.t
|
||||
t/cipher_seed_test_vectors_bc.t
|
||||
t/cipher_skipjack.t
|
||||
t/cipher_stream.t
|
||||
t/cipher_test_vectors_ltc.t
|
||||
t/cipher_test_vectors_openssl.t
|
||||
t/cipher_twofish.t
|
||||
t/cipher_twofish_test_vectors_bc.t
|
||||
t/cipher_xtea.t
|
||||
t/cipher_xtea_test_vectors_bc.t
|
||||
t/crypt-misc.t
|
||||
t/data/binary-test.file
|
||||
t/data/cryptx_priv_dh1.bin
|
||||
t/data/cryptx_priv_dh2.bin
|
||||
t/data/cryptx_priv_dh_pg1.bin
|
||||
t/data/cryptx_priv_dh_pg2.bin
|
||||
t/data/cryptx_priv_dsa1.der
|
||||
t/data/cryptx_priv_dsa1.pem
|
||||
t/data/cryptx_priv_dsa2.der
|
||||
t/data/cryptx_priv_dsa2.pem
|
||||
t/data/cryptx_priv_ecc1.der
|
||||
t/data/cryptx_priv_ecc1.pem
|
||||
t/data/cryptx_priv_ecc1_OLD.der
|
||||
t/data/cryptx_priv_ecc1_OLD.pem
|
||||
t/data/cryptx_priv_ecc2.der
|
||||
t/data/cryptx_priv_ecc2.pem
|
||||
t/data/cryptx_priv_ecc2_OLD.der
|
||||
t/data/cryptx_priv_ecc2_OLD.pem
|
||||
t/data/cryptx_priv_rsa1.der
|
||||
t/data/cryptx_priv_rsa1.pem
|
||||
t/data/cryptx_priv_rsa2.der
|
||||
t/data/cryptx_priv_rsa2.pem
|
||||
t/data/cryptx_pub_dh1.bin
|
||||
t/data/cryptx_pub_dh2.bin
|
||||
t/data/cryptx_pub_dh_pg1.bin
|
||||
t/data/cryptx_pub_dh_pg2.bin
|
||||
t/data/cryptx_pub_dsa1.der
|
||||
t/data/cryptx_pub_dsa1.pem
|
||||
t/data/cryptx_pub_dsa2.der
|
||||
t/data/cryptx_pub_dsa2.pem
|
||||
t/data/cryptx_pub_ecc1.der
|
||||
t/data/cryptx_pub_ecc1.pem
|
||||
t/data/cryptx_pub_ecc1_OLD.der
|
||||
t/data/cryptx_pub_ecc1_OLD.pem
|
||||
t/data/cryptx_pub_ecc2.der
|
||||
t/data/cryptx_pub_ecc2.pem
|
||||
t/data/cryptx_pub_ecc2_OLD.der
|
||||
t/data/cryptx_pub_ecc2_OLD.pem
|
||||
t/data/cryptx_pub_rsa1.der
|
||||
t/data/cryptx_pub_rsa1.pem
|
||||
t/data/cryptx_pub_rsa2.der
|
||||
t/data/cryptx_pub_rsa2.pem
|
||||
t/data/dsa-aes128.pem
|
||||
t/data/dsa-aes192.pem
|
||||
t/data/dsa-aes256.pem
|
||||
t/data/dsa-camellia128.pem
|
||||
t/data/dsa-camellia192.pem
|
||||
t/data/dsa-camellia256.pem
|
||||
t/data/dsa-des.pem
|
||||
t/data/dsa-des3.pem
|
||||
t/data/dsa-param.pem
|
||||
t/data/dsa-seed.pem
|
||||
t/data/ec-aes128.pem
|
||||
t/data/ec-aes192.pem
|
||||
t/data/ec-aes256.pem
|
||||
t/data/ec-camellia128.pem
|
||||
t/data/ec-camellia192.pem
|
||||
t/data/ec-camellia256.pem
|
||||
t/data/ec-des.pem
|
||||
t/data/ec-des3.pem
|
||||
t/data/ec-seed.pem
|
||||
t/data/jwk_ec-priv1.json
|
||||
t/data/jwk_ec-pub.json
|
||||
t/data/jwk_ec-pub1.json
|
||||
t/data/jwk_rsa-priv.json
|
||||
t/data/jwk_rsa-priv1.json
|
||||
t/data/jwk_rsa-pub1.json
|
||||
t/data/openssl_dsa1.der
|
||||
t/data/openssl_dsa1.pem
|
||||
t/data/openssl_dsa2.der
|
||||
t/data/openssl_dsa2.pem
|
||||
t/data/openssl_ec-short.der
|
||||
t/data/openssl_ec-short.pem
|
||||
t/data/openssl_ec-short.pub.der
|
||||
t/data/openssl_ec-short.pub.pem
|
||||
t/data/openssl_ec1.key.pem
|
||||
t/data/openssl_ec1.pri.der
|
||||
t/data/openssl_ec1.pri.pem
|
||||
t/data/openssl_ec1.pric.der
|
||||
t/data/openssl_ec1.pric.pem
|
||||
t/data/openssl_ec1.pub.der
|
||||
t/data/openssl_ec1.pub.pem
|
||||
t/data/openssl_ec1.pubc.der
|
||||
t/data/openssl_ec1.pubc.pem
|
||||
t/data/openssl_rsa1.der
|
||||
t/data/openssl_rsa1.pem
|
||||
t/data/openssl_rsa1.pubonly.der
|
||||
t/data/openssl_rsa1.pubonly.pem
|
||||
t/data/openssl_rsa2.der
|
||||
t/data/openssl_rsa2.pem
|
||||
t/data/openssl_rsa2.pubonly.der
|
||||
t/data/openssl_rsa2.pubonly.pem
|
||||
t/data/pkcs8.ec-priv-nopass.der
|
||||
t/data/pkcs8.ec-priv-nopass.pem
|
||||
t/data/pkcs8.ec-priv-pass.der
|
||||
t/data/pkcs8.ec-priv-pass.pem
|
||||
t/data/pkcs8.ec-short-priv-nopass.der
|
||||
t/data/pkcs8.ec-short-priv-nopass.pem
|
||||
t/data/pkcs8.ec-short-priv-pass.der
|
||||
t/data/pkcs8.ec-short-priv-pass.pem
|
||||
t/data/pkcs8.rsa-priv-nopass.der
|
||||
t/data/pkcs8.rsa-priv-nopass.pem
|
||||
t/data/pkcs8.rsa-priv-pass.der
|
||||
t/data/pkcs8.rsa-priv-pass.pem
|
||||
t/data/rsa-aes128.pem
|
||||
t/data/rsa-aes192.pem
|
||||
t/data/rsa-aes256.pem
|
||||
t/data/rsa-camellia128.pem
|
||||
t/data/rsa-camellia192.pem
|
||||
t/data/rsa-camellia256.pem
|
||||
t/data/rsa-des.pem
|
||||
t/data/rsa-des3.pem
|
||||
t/data/rsa-seed.pem
|
||||
t/data/ssh/ssh_dsa_1024
|
||||
t/data/ssh/ssh_dsa_1024.pub
|
||||
t/data/ssh/ssh_dsa_1024.pub.pkcs8
|
||||
t/data/ssh/ssh_dsa_1024.pub.rfc4716
|
||||
t/data/ssh/ssh_ecdsa_256
|
||||
t/data/ssh/ssh_ecdsa_256.pub
|
||||
t/data/ssh/ssh_ecdsa_256.pub.pkcs8
|
||||
t/data/ssh/ssh_ecdsa_256.pub.rfc4716
|
||||
t/data/ssh/ssh_ecdsa_384
|
||||
t/data/ssh/ssh_ecdsa_384.pub
|
||||
t/data/ssh/ssh_ecdsa_384.pub.pkcs8
|
||||
t/data/ssh/ssh_ecdsa_384.pub.rfc4716
|
||||
t/data/ssh/ssh_ecdsa_521
|
||||
t/data/ssh/ssh_ecdsa_521.pub
|
||||
t/data/ssh/ssh_ecdsa_521.pub.pkcs8
|
||||
t/data/ssh/ssh_ecdsa_521.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_1024
|
||||
t/data/ssh/ssh_rsa_1024.pub
|
||||
t/data/ssh/ssh_rsa_1024.pub.pem
|
||||
t/data/ssh/ssh_rsa_1024.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_1024.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_1024_passwd
|
||||
t/data/ssh/ssh_rsa_1536
|
||||
t/data/ssh/ssh_rsa_1536.pub
|
||||
t/data/ssh/ssh_rsa_1536.pub.pem
|
||||
t/data/ssh/ssh_rsa_1536.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_1536.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_1536_passwd
|
||||
t/data/ssh/ssh_rsa_2048
|
||||
t/data/ssh/ssh_rsa_2048.pub
|
||||
t/data/ssh/ssh_rsa_2048.pub.pem
|
||||
t/data/ssh/ssh_rsa_2048.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_2048.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_2048_passwd
|
||||
t/data/ssh/ssh_rsa_4096
|
||||
t/data/ssh/ssh_rsa_4096.pub
|
||||
t/data/ssh/ssh_rsa_4096.pub.pem
|
||||
t/data/ssh/ssh_rsa_4096.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_4096.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_4096_passwd
|
||||
t/data/ssh/ssh_rsa_768
|
||||
t/data/ssh/ssh_rsa_768.pub
|
||||
t/data/ssh/ssh_rsa_768.pub.pem
|
||||
t/data/ssh/ssh_rsa_768.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_768.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_768_passwd
|
||||
t/data/ssh/ssh_rsa_8192
|
||||
t/data/ssh/ssh_rsa_8192.pub
|
||||
t/data/ssh/ssh_rsa_8192.pub.pem
|
||||
t/data/ssh/ssh_rsa_8192.pub.pkcs8
|
||||
t/data/ssh/ssh_rsa_8192.pub.rfc4716
|
||||
t/data/ssh/ssh_rsa_8192_passwd
|
||||
t/data/text-CR.file
|
||||
t/data/text-CRLF.file
|
||||
t/data/text-LF.file
|
||||
t/digest_blake2b_160.t
|
||||
t/digest_blake2b_256.t
|
||||
t/digest_blake2b_384.t
|
||||
t/digest_blake2b_512.t
|
||||
t/digest_blake2s_128.t
|
||||
t/digest_blake2s_160.t
|
||||
t/digest_blake2s_224.t
|
||||
t/digest_blake2s_256.t
|
||||
t/digest_chaes.t
|
||||
t/digest_md2.t
|
||||
t/digest_md4.t
|
||||
t/digest_md5.t
|
||||
t/digest_ripemd128.t
|
||||
t/digest_ripemd160.t
|
||||
t/digest_ripemd256.t
|
||||
t/digest_ripemd320.t
|
||||
t/digest_sha1.t
|
||||
t/digest_sha224.t
|
||||
t/digest_sha256.t
|
||||
t/digest_sha384.t
|
||||
t/digest_sha3_224.t
|
||||
t/digest_sha3_256.t
|
||||
t/digest_sha3_384.t
|
||||
t/digest_sha3_512.t
|
||||
t/digest_sha512.t
|
||||
t/digest_sha512_224.t
|
||||
t/digest_sha512_256.t
|
||||
t/digest_shake.t
|
||||
t/digest_test_vectors_ltc.t
|
||||
t/digest_tiger192.t
|
||||
t/digest_whirlpool.t
|
||||
t/jwk.t
|
||||
t/key_derivation.t
|
||||
t/mac_blake2b.t
|
||||
t/mac_blake2s.t
|
||||
t/mac_f9.t
|
||||
t/mac_hmac.t
|
||||
t/mac_hmac_test_vectors_ltc.t
|
||||
t/mac_omac.t
|
||||
t/mac_omac_test_vectors_ltc.t
|
||||
t/mac_pelican.t
|
||||
t/mac_pmac.t
|
||||
t/mac_pmac_test_vectors_ltc.t
|
||||
t/mac_poly1305.t
|
||||
t/mac_xcbc.t
|
||||
t/mbi_ltm/bigfltpm.inc
|
||||
t/mbi_ltm/bigintpm.inc
|
||||
t/mbi_ltm_01load.t
|
||||
t/mbi_ltm_bigfltpm.t
|
||||
t/mbi_ltm_bigintg.t
|
||||
t/mbi_ltm_bigintpm.t
|
||||
t/mbi_ltm_biglog.t
|
||||
t/mbi_ltm_bigroot.t
|
||||
t/mbi_ltm_bugs.t
|
||||
t/mbi_ltm_mbi-from-big-scalar.t
|
||||
t/mbi_ltm_storable.t
|
||||
t/mode_cbc.t
|
||||
t/mode_cfb.t
|
||||
t/mode_ctr.t
|
||||
t/mode_ecb.t
|
||||
t/mode_ofb.t
|
||||
t/pk_dh.t
|
||||
t/pk_dsa.t
|
||||
t/pk_dsa_test_vectors_openssl.t
|
||||
t/pk_ecc.t
|
||||
t/pk_ecc_test_vectors_openssl.t
|
||||
t/pk_enc_pem.t
|
||||
t/pk_rsa.t
|
||||
t/pk_rsa_test_vectors_openssl.t
|
||||
t/pkcs8.t
|
||||
t/prng.t
|
||||
t/prng_chacha20.t
|
||||
t/prng_fortuna.t
|
||||
t/prng_rc4.t
|
||||
t/prng_sober128.t
|
||||
t/prng_yarrow.t
|
||||
t/sshkey.t
|
||||
typemap
|
50
META.json
Normal file
50
META.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"abstract" : "Crypto toolkit",
|
||||
"author" : [
|
||||
"Karel Miko"
|
||||
],
|
||||
"dynamic_config" : 1,
|
||||
"generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010",
|
||||
"license" : [
|
||||
"perl_5"
|
||||
],
|
||||
"meta-spec" : {
|
||||
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
|
||||
"version" : "2"
|
||||
},
|
||||
"name" : "CryptX",
|
||||
"no_index" : {
|
||||
"directory" : [
|
||||
"t",
|
||||
"inc"
|
||||
]
|
||||
},
|
||||
"prereqs" : {
|
||||
"build" : {
|
||||
"requires" : {
|
||||
"ExtUtils::MakeMaker" : "0"
|
||||
}
|
||||
},
|
||||
"configure" : {
|
||||
"requires" : {
|
||||
"ExtUtils::MakeMaker" : "0"
|
||||
}
|
||||
},
|
||||
"runtime" : {
|
||||
"requires" : {
|
||||
"perl" : "5.006"
|
||||
}
|
||||
}
|
||||
},
|
||||
"release_status" : "stable",
|
||||
"resources" : {
|
||||
"bugtracker" : {
|
||||
"web" : "https://github.com/DCIT/perl-CryptX/issues"
|
||||
},
|
||||
"repository" : {
|
||||
"url" : "https://github.com/DCIT/perl-CryptX"
|
||||
}
|
||||
},
|
||||
"version" : "0.048",
|
||||
"x_serialization_backend" : "JSON::PP version 2.27400"
|
||||
}
|
26
META.yml
Normal file
26
META.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
abstract: 'Crypto toolkit'
|
||||
author:
|
||||
- 'Karel Miko'
|
||||
build_requires:
|
||||
ExtUtils::MakeMaker: '0'
|
||||
configure_requires:
|
||||
ExtUtils::MakeMaker: '0'
|
||||
dynamic_config: 1
|
||||
generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010'
|
||||
license: perl
|
||||
meta-spec:
|
||||
url: http://module-build.sourceforge.net/META-spec-v1.4.html
|
||||
version: '1.4'
|
||||
name: CryptX
|
||||
no_index:
|
||||
directory:
|
||||
- t
|
||||
- inc
|
||||
requires:
|
||||
perl: '5.006'
|
||||
resources:
|
||||
bugtracker: https://github.com/DCIT/perl-CryptX/issues
|
||||
repository: https://github.com/DCIT/perl-CryptX
|
||||
version: '0.048'
|
||||
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
|
87
Makefile.PL
Normal file
87
Makefile.PL
Normal file
@ -0,0 +1,87 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use ExtUtils::MakeMaker;
|
||||
use Config;
|
||||
|
||||
my @myobjs = map { s|.c$|$Config{obj_ext}|; $_ } grep { $_ !~ m|^src/ltc/\.*tab\.c$| } (
|
||||
glob('src/ltm/*.c'),
|
||||
glob('src/ltc/*/*.c'),
|
||||
glob('src/ltc/*/*/*.c'),
|
||||
glob('src/ltc/*/*/*/*.c'),
|
||||
glob('src/ltc/*/*/*/*/*.c'),
|
||||
);
|
||||
my $myextlib = "src/liballinone$Config{lib_ext}";
|
||||
my $mycflags = "$Config{cccdlflags} $Config{ccflags} $Config{optimize} -Iltm -Iltc/headers -DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC";
|
||||
|
||||
#FIX: gcc with -flto is a trouble maker see https://github.com/DCIT/perl-CryptX/issues/32
|
||||
$mycflags =~ s/-flto\b//g;
|
||||
|
||||
#FIX: avoid "ar: fatal: Numeric group ID too large" see https://github.com/DCIT/perl-CryptX/issues/33
|
||||
my $myarflags = '$(AR_STATIC_ARGS)';
|
||||
if ($^O ne 'MSWin32' && $Config{ar}) {
|
||||
# for ar's "deterministic mode" we need GNU binutils 2.20+ (2009-10-16)
|
||||
my $arver = `$Config{ar} --version`;
|
||||
my ($maj, $min) = $arver =~ /^GNU ar [^\d]*(\d)\.(\d+)\.\d+/s;
|
||||
$myarflags = 'rcD' if ($maj && $min && $maj >= 2 && $min >= 20) || $arver=~ /^BSD ar /;
|
||||
}
|
||||
|
||||
my %eumm_args = (
|
||||
NAME => 'CryptX',
|
||||
VERSION_FROM => 'lib/CryptX.pm',
|
||||
AUTHOR => 'Karel Miko',
|
||||
ABSTRACT => 'Crypto toolkit',
|
||||
MIN_PERL_VERSION => '5.006',
|
||||
LICENSE => 'perl_5',
|
||||
META_MERGE => { resources => { repository => 'https://github.com/DCIT/perl-CryptX', bugtracker => 'https://github.com/DCIT/perl-CryptX/issues' } },
|
||||
DEFINE => '-DLTC_SOURCE -DLTC_NO_TEST -DLTC_NO_PROTOTYPES -DLTM_DESC',
|
||||
INC => '-Isrc/ltc/headers -Isrc/ltm',
|
||||
LIBS => [''],
|
||||
MYEXTLIB => $myextlib,
|
||||
clean => { 'FILES' => join(' ', @myobjs, $myextlib) },
|
||||
);
|
||||
|
||||
my $eumm_ver = eval $ExtUtils::MakeMaker::VERSION;
|
||||
delete $eumm_args{MIN_PERL_VERSION} if $eumm_ver < 6.48;
|
||||
delete $eumm_args{META_ADD} if $eumm_ver < 6.46;
|
||||
delete $eumm_args{META_MERGE} if $eumm_ver < 6.46;
|
||||
delete $eumm_args{LICENSE} if $eumm_ver < 6.31;
|
||||
|
||||
WriteMakefile(%eumm_args);
|
||||
|
||||
# ARFLAGS=\$(AR_STATIC_ARGS) RANLIB=\$(RANLIB) AR=\$(AR)
|
||||
|
||||
sub MY::postamble {
|
||||
my $myextlib = qq{
|
||||
\$(MYEXTLIB): src/Makefile
|
||||
cd src && \$(MAKE) ARFLAGS="$myarflags" RANLIB="\$(RANLIB)" AR="\$(AR)" CC="\$(CC)" LIB_EXT=\$(LIB_EXT) OBJ_EXT=\$(OBJ_EXT) CFLAGS="$mycflags"
|
||||
};
|
||||
|
||||
$myextlib = qq{
|
||||
\$(MYEXTLIB): src/Makefile
|
||||
cd src && \$(MAKE) -f Makefile.nmake CFLAGS="$mycflags"
|
||||
} if $^O eq 'MSWin32' && $Config{make} =~ /nmake/ && $Config{cc} =~ /cl/;
|
||||
|
||||
$myextlib = qq{
|
||||
\$(MYEXTLIB): src/Makefile
|
||||
cd src && \$(MAKE) CC="$Config{cc}" CFLAGS="$mycflags"
|
||||
} if $^O eq 'MSWin32' && $Config{cc} =~ /gcc/;
|
||||
|
||||
my $version_patch = q{
|
||||
versionsync:
|
||||
$(NOECHO) perl _generators/version_patch.pl sync
|
||||
|
||||
versioninc:
|
||||
$(NOECHO) perl _generators/version_patch.pl inc
|
||||
|
||||
versionincdev:
|
||||
$(NOECHO) perl _generators/version_patch.pl incdev
|
||||
|
||||
versiondec:
|
||||
$(NOECHO) perl _generators/version_patch.pl dec
|
||||
|
||||
versiondecdev:
|
||||
$(NOECHO) perl _generators/version_patch.pl decdev
|
||||
};
|
||||
|
||||
return "$myextlib\n$version_patch";
|
||||
}
|
68
README
Normal file
68
README
Normal file
@ -0,0 +1,68 @@
|
||||
NAME
|
||||
CryptX - Crypto toolkit (self-contained no external libraries needed)
|
||||
|
||||
DESCRIPTION
|
||||
Cryptography in CryptX is based on
|
||||
<https://github.com/libtom/libtomcrypt>
|
||||
|
||||
Currently available modules:
|
||||
|
||||
* Ciphers - see Crypt::Cipher and related modules
|
||||
|
||||
Crypt::Cipher::AES, Crypt::Cipher::Anubis, Crypt::Cipher::Blowfish,
|
||||
Crypt::Cipher::Camellia, Crypt::Cipher::CAST5, Crypt::Cipher::DES,
|
||||
Crypt::Cipher::DES_EDE, Crypt::Cipher::KASUMI,
|
||||
Crypt::Cipher::Khazad, Crypt::Cipher::MULTI2,
|
||||
Crypt::Cipher::Noekeon, Crypt::Cipher::RC2, Crypt::Cipher::RC5,
|
||||
Crypt::Cipher::RC6, Crypt::Cipher::SAFERP,
|
||||
Crypt::Cipher::SAFER_K128, Crypt::Cipher::SAFER_K64,
|
||||
Crypt::Cipher::SAFER_SK128, Crypt::Cipher::SAFER_SK64,
|
||||
Crypt::Cipher::SEED, Crypt::Cipher::Skipjack,
|
||||
Crypt::Cipher::Twofish, Crypt::Cipher::XTEA
|
||||
|
||||
* Block cipher modes
|
||||
|
||||
Crypt::Mode::CBC, Crypt::Mode::CFB, Crypt::Mode::CTR,
|
||||
Crypt::Mode::ECB, Crypt::Mode::OFB
|
||||
|
||||
* Authenticated encryption modes
|
||||
|
||||
Crypt::AuthEnc::CCM, Crypt::AuthEnc::EAX, Crypt::AuthEnc::GCM,
|
||||
Crypt::AuthEnc::OCB
|
||||
|
||||
* Hash Functions - see Crypt::Digest and related modules
|
||||
|
||||
Crypt::Digest::CHAES, Crypt::Digest::MD2, Crypt::Digest::MD4,
|
||||
Crypt::Digest::MD5, Crypt::Digest::RIPEMD128,
|
||||
Crypt::Digest::RIPEMD160, Crypt::Digest::RIPEMD256,
|
||||
Crypt::Digest::RIPEMD320, Crypt::Digest::SHA1,
|
||||
Crypt::Digest::SHA224, Crypt::Digest::SHA256, Crypt::Digest::SHA384,
|
||||
Crypt::Digest::SHA512, Crypt::Digest::SHA512_224,
|
||||
Crypt::Digest::SHA512_256, Crypt::Digest::Tiger192,
|
||||
Crypt::Digest::Whirlpool
|
||||
|
||||
* Message Authentication Codes
|
||||
|
||||
Crypt::Mac::F9, Crypt::Mac::HMAC, Crypt::Mac::OMAC,
|
||||
Crypt::Mac::Pelican, Crypt::Mac::PMAC, Crypt::Mac::XCBC
|
||||
|
||||
* Public key cryptography
|
||||
|
||||
Crypt::PK::RSA, Crypt::PK::DSA, Crypt::PK::ECC, Crypt::PK::DH
|
||||
|
||||
* Cryptographically secure random number generators
|
||||
|
||||
Crypt::PRNG, Crypt::PRNG::Fortuna, Crypt::PRNG::Yarrow,
|
||||
Crypt::PRNG::RC4, Crypt::PRNG::Sober128
|
||||
|
||||
* Key derivation functions - PBKDF1, PBKFD2 and HKDF
|
||||
|
||||
Crypt::KeyDerivation
|
||||
|
||||
LICENSE
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the same terms as Perl itself.
|
||||
|
||||
COPYRIGHT
|
||||
Copyright (c) 2013-2015 DCIT, a.s. <http://www.dcit.cz> / Karel Miko
|
||||
|
90
inc/CryptX_AuthEnc_CCM.xs.inc
Normal file
90
inc/CryptX_AuthEnc_CCM.xs.inc
Normal file
@ -0,0 +1,90 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::AuthEnc::CCM
|
||||
|
||||
void
|
||||
_memory_encrypt(char *cipher_name, SV *key, SV *nonce, SV *header, unsigned long tag_len, SV *plaintext)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN k_len, n_len, h_len, pt_len;
|
||||
unsigned char *k, *n, *h, *pt;
|
||||
int rv, id;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
SV *ct;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
if (!SvPOK(header)) croak("FATAL: header must be string/buffer scalar");
|
||||
if (!SvPOK(plaintext)) croak("FATAL: plaintext must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
n = (unsigned char *) SvPVbyte(nonce, n_len);
|
||||
h = (unsigned char *) SvPVbyte(header, h_len);
|
||||
pt = (unsigned char *) SvPVbyte(plaintext, pt_len);
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
ct = NEWSV(0, pt_len);
|
||||
SvPOK_only(ct);
|
||||
SvCUR_set(ct, pt_len);
|
||||
|
||||
if(tag_len<4 || tag_len>16) tag_len = 16;
|
||||
|
||||
rv = ccm_memory(id, k, (unsigned long)k_len, NULL, n, (unsigned long)n_len, h, (unsigned long)h_len,
|
||||
pt, (unsigned long)pt_len, (unsigned char *)SvPV_nolen(ct), tag, &tag_len, CCM_ENCRYPT);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ccm_memory failed: %s", error_to_string(rv));
|
||||
|
||||
XPUSHs(sv_2mortal(ct));
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag,tag_len)));
|
||||
|
||||
/* int ccm_memory( int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
symmetric_key *uskey,
|
||||
const unsigned char *nonce, unsigned long noncelen,
|
||||
const unsigned char *header, unsigned long headerlen,
|
||||
unsigned char *pt, unsigned long ptlen,
|
||||
unsigned char *ct,
|
||||
unsigned char *tag, unsigned long *taglen,
|
||||
int direction); */
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
_memory_decrypt(char *cipher_name, SV *key, SV *nonce, SV *header, SV *ciphertext, SV *tag)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN k_len, n_len, h_len, ct_len, t_len;
|
||||
unsigned char *k, *n, *h, *ct, *t;
|
||||
int rv, id;
|
||||
unsigned char xtag[MAXBLOCKSIZE];
|
||||
unsigned long xtag_len;
|
||||
SV *pt;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
if (!SvPOK(header)) croak("FATAL: header must be string/buffer scalar");
|
||||
if (!SvPOK(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar");
|
||||
if (!SvPOK(tag)) croak("FATAL: tag must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
n = (unsigned char *) SvPVbyte(nonce, n_len);
|
||||
h = (unsigned char *) SvPVbyte(header, h_len);
|
||||
ct = (unsigned char *) SvPVbyte(ciphertext, ct_len);
|
||||
t = (unsigned char *) SvPVbyte(tag, t_len);
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
pt = NEWSV(0, ct_len);
|
||||
SvPOK_only(pt);
|
||||
SvCUR_set(pt, ct_len);
|
||||
|
||||
xtag_len = (unsigned long)t_len;
|
||||
Copy(t, xtag, t_len, unsigned char);
|
||||
|
||||
rv = ccm_memory(id, k, (unsigned long)k_len, NULL, n, (unsigned long)n_len, h, (unsigned long)h_len,
|
||||
(unsigned char *)SvPV_nolen(pt), (unsigned long)ct_len, ct, xtag, &xtag_len, CCM_DECRYPT);
|
||||
if (rv != CRYPT_OK) {
|
||||
XPUSHs(sv_2mortal(newSVpvn(NULL,0))); /* undef */
|
||||
}
|
||||
else {
|
||||
XPUSHs(sv_2mortal(pt));
|
||||
}
|
||||
}
|
185
inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc
Normal file
185
inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc
Normal file
@ -0,0 +1,185 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::AuthEnc::ChaCha20Poly1305
|
||||
|
||||
Crypt::AuthEnc::ChaCha20Poly1305
|
||||
_new(SV * key, SV * nonce = NULL)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN iv_len=0, k_len=0;
|
||||
unsigned char *iv=NULL, *k=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
if (nonce) {
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
iv = (unsigned char *) SvPVbyte(nonce, iv_len);
|
||||
}
|
||||
|
||||
Newz(0, RETVAL, 1, struct chacha20poly1305_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = chacha20poly1305_init(&RETVAL->state, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_init failed: %s", error_to_string(rv));
|
||||
|
||||
if (iv && iv_len > 0) {
|
||||
rv = chacha20poly1305_setiv(&RETVAL->state, iv, (unsigned long)iv_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::AuthEnc::ChaCha20Poly1305 self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::AuthEnc::ChaCha20Poly1305
|
||||
clone(Crypt::AuthEnc::ChaCha20Poly1305 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct chacha20poly1305_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct chacha20poly1305_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
set_iv(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN iv_len=0;
|
||||
unsigned char *iv=NULL;
|
||||
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
iv = (unsigned char *) SvPVbyte(nonce, iv_len);
|
||||
rv = chacha20poly1305_setiv(&self->state, iv, (unsigned long)iv_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
set_iv_rfc7905(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce, UV seqnum)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN iv_len=0;
|
||||
unsigned char *iv=NULL;
|
||||
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
iv = (unsigned char *) SvPVbyte(nonce, iv_len);
|
||||
rv = chacha20poly1305_setiv_rfc7905(&self->state, iv, (unsigned long)iv_len, (ulong64)seqnum);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv_rfc7905 failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
adata_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
rv = chacha20poly1305_add_aad(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_add_aad failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = chacha20poly1305_decrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
encrypt_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = chacha20poly1305_encrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
encrypt_done(Crypt::AuthEnc::ChaCha20Poly1305 self)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
|
||||
rv = chacha20poly1305_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv));
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
|
||||
void
|
||||
decrypt_done(Crypt::AuthEnc::ChaCha20Poly1305 self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
STRLEN expected_tag_len;
|
||||
unsigned char *expected_tag;
|
||||
|
||||
rv = chacha20poly1305_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv));
|
||||
if (items == 1) {
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
else {
|
||||
if(!SvPOK(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar");
|
||||
expected_tag = (unsigned char *) SvPVbyte(ST(1), expected_tag_len);
|
||||
if (expected_tag_len!=tag_len) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else if (memNE(expected_tag, tag, tag_len)) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else {
|
||||
XPUSHs(sv_2mortal(newSViv(1))); /* true */
|
||||
}
|
||||
}
|
||||
}
|
152
inc/CryptX_AuthEnc_EAX.xs.inc
Normal file
152
inc/CryptX_AuthEnc_EAX.xs.inc
Normal file
@ -0,0 +1,152 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::AuthEnc::EAX
|
||||
|
||||
Crypt::AuthEnc::EAX
|
||||
_new(char * cipher_name, SV * key, SV * nonce, SV * adata=&PL_sv_undef)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
unsigned char *n=NULL;
|
||||
STRLEN n_len=0;
|
||||
unsigned char *h=NULL;
|
||||
STRLEN h_len=0;
|
||||
int id;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
n = (unsigned char *) SvPVbyte(nonce, n_len);
|
||||
if(SvOK(adata)) { /* adata is optional param */
|
||||
if(!SvPOK(adata)) croak("FATAL: adata must be string/buffer scalar");
|
||||
h = (unsigned char *) SvPVbyte(adata, h_len);
|
||||
}
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
Newz(0, RETVAL, 1, struct eax_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
if (eax_init(&RETVAL->state, id, k, (unsigned long)k_len, n, (unsigned long)n_len, h, (unsigned long)h_len) != CRYPT_OK) {
|
||||
croak("FATAL: eax setup failed");
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::AuthEnc::EAX self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::AuthEnc::EAX
|
||||
clone(Crypt::AuthEnc::EAX self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct eax_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct eax_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
encrypt_add(Crypt::AuthEnc::EAX self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = eax_encrypt(&self->state, in_data, out_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: eax_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt_add(Crypt::AuthEnc::EAX self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = eax_decrypt(&self->state, in_data, out_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: eax_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
encrypt_done(Crypt::AuthEnc::EAX self)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
|
||||
rv = eax_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: eax_done failed: %s", error_to_string(rv));
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
|
||||
void
|
||||
decrypt_done(Crypt::AuthEnc::EAX self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
STRLEN expected_tag_len;
|
||||
unsigned char *expected_tag;
|
||||
|
||||
rv = eax_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: eax_done failed: %s", error_to_string(rv));
|
||||
if (items == 1) {
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
else {
|
||||
if(!SvPOK(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar");
|
||||
expected_tag = (unsigned char *) SvPVbyte(ST(1), expected_tag_len);
|
||||
if (expected_tag_len!=tag_len) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else if (memNE(expected_tag, tag, tag_len)) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else {
|
||||
XPUSHs(sv_2mortal(newSViv(1))); /* true */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
aad_add(Crypt::AuthEnc::EAX self, SV * adata)
|
||||
CODE:
|
||||
{
|
||||
STRLEN h_len;
|
||||
unsigned char *h;
|
||||
h = (unsigned char *)SvPVbyte(adata, h_len);
|
||||
RETVAL = eax_addheader(&self->state, h, (unsigned long)h_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
184
inc/CryptX_AuthEnc_GCM.xs.inc
Normal file
184
inc/CryptX_AuthEnc_GCM.xs.inc
Normal file
@ -0,0 +1,184 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::AuthEnc::GCM
|
||||
|
||||
Crypt::AuthEnc::GCM
|
||||
_new(char * cipher_name, SV * key, SV * nonce = NULL)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len = 0, iv_len = 0;
|
||||
unsigned char *k = NULL, *iv = NULL;
|
||||
int id, rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
if (nonce) {
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
iv = (unsigned char *)SvPVbyte(nonce, iv_len);
|
||||
}
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
Newz(0, RETVAL, 1, struct gcm_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = gcm_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_init failed: %s", error_to_string(rv));
|
||||
|
||||
if (iv && iv_len > 0) {
|
||||
rv = gcm_add_iv(&RETVAL->state, iv, (unsigned long)iv_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_add_iv failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::AuthEnc::GCM self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::AuthEnc::GCM
|
||||
clone(Crypt::AuthEnc::GCM self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct gcm_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct gcm_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
reset(Crypt::AuthEnc::GCM self)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
rv = gcm_reset(&self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_reset failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
encrypt_add(Crypt::AuthEnc::GCM self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = gcm_process(&self->state, in_data, (unsigned long)in_data_len, out_data, GCM_ENCRYPT);
|
||||
if (rv != CRYPT_OK) croak("FATAL: encrypt_add/gcm_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
iv_add(Crypt::AuthEnc::GCM self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
rv = gcm_add_iv(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_add_iv failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
adata_add(Crypt::AuthEnc::GCM self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
rv = gcm_add_aad(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_add_aad failed: %s", error_to_string(rv));
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt_add(Crypt::AuthEnc::GCM self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = gcm_process(&self->state, out_data, (unsigned long)in_data_len, in_data, GCM_DECRYPT);
|
||||
if (rv != CRYPT_OK) croak("FATAL: encrypt_add/gcm_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
|
||||
void
|
||||
encrypt_done(Crypt::AuthEnc::GCM self)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
|
||||
rv = gcm_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_done failed: %s", error_to_string(rv));
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
|
||||
void
|
||||
decrypt_done(Crypt::AuthEnc::GCM self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
STRLEN expected_tag_len;
|
||||
unsigned char *expected_tag;
|
||||
|
||||
rv = gcm_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: gcm_done failed: %s", error_to_string(rv));
|
||||
if (items == 1) {
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
else {
|
||||
if(!SvPOK(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar");
|
||||
expected_tag = (unsigned char *) SvPVbyte(ST(1), expected_tag_len);
|
||||
if (expected_tag_len!=tag_len) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else if (memNE(expected_tag, tag, tag_len)) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else {
|
||||
XPUSHs(sv_2mortal(newSViv(1))); /* true */
|
||||
}
|
||||
}
|
||||
}
|
218
inc/CryptX_AuthEnc_OCB.xs.inc
Normal file
218
inc/CryptX_AuthEnc_OCB.xs.inc
Normal file
@ -0,0 +1,218 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::AuthEnc::OCB
|
||||
|
||||
Crypt::AuthEnc::OCB
|
||||
_new(char * cipher_name, SV * key, SV * nonce)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
unsigned char *n=NULL;
|
||||
STRLEN n_len=0;
|
||||
int id;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
n = (unsigned char *) SvPVbyte(nonce, n_len);
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
Newz(0, RETVAL, 1, struct ocb_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
if (ocb3_init(&RETVAL->state, id, k, (unsigned long)k_len, n, (unsigned long)n_len) != CRYPT_OK) {
|
||||
croak("FATAL: ocb setup failed");
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::AuthEnc::OCB self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::AuthEnc::OCB
|
||||
clone(Crypt::AuthEnc::OCB self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct ocb_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct ocb_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
aad_add(Crypt::AuthEnc::OCB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
|
||||
if (in_data_len>0) {
|
||||
rv = ocb3_add_aad(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_add_aad failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
encrypt_add(Crypt::AuthEnc::OCB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (in_data_len % (&self->state)->block_len)
|
||||
croak ("FATAL: sizeof(data) should be multiple of blocksize (%d)", (&self->state)->block_len);
|
||||
|
||||
rv = ocb3_encrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
encrypt_last(Crypt::AuthEnc::OCB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
out_data = NULL;
|
||||
}
|
||||
rv = ocb3_encrypt_last(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_encrypt_last failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt_add(Crypt::AuthEnc::OCB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (in_data_len % (&self->state)->block_len)
|
||||
croak ("FATAL: sizeof(data) should be multiple of blocksize (%d)", (&self->state)->block_len);
|
||||
|
||||
rv = ocb3_decrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt_last(Crypt::AuthEnc::OCB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
out_data = NULL;
|
||||
}
|
||||
rv = ocb3_decrypt_last(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_encrypt_last failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
encrypt_done(Crypt::AuthEnc::OCB self)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
|
||||
rv = ocb3_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_done_encrypt failed: %s", error_to_string(rv));
|
||||
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
|
||||
void
|
||||
decrypt_done(Crypt::AuthEnc::OCB self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char tag[MAXBLOCKSIZE];
|
||||
unsigned long tag_len = sizeof(tag);
|
||||
STRLEN expected_tag_len;
|
||||
unsigned char *expected_tag;
|
||||
|
||||
rv = ocb3_done(&self->state, tag, &tag_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ocb3_done_decrypt failed: %s", error_to_string(rv));
|
||||
if (items == 1) {
|
||||
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
|
||||
}
|
||||
else {
|
||||
if(!SvPOK(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar");
|
||||
expected_tag = (unsigned char *) SvPVbyte(ST(1), expected_tag_len);
|
||||
if (expected_tag_len!=tag_len) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else if (memNE(expected_tag, tag, tag_len)) {
|
||||
XPUSHs(sv_2mortal(newSViv(0))); /* false */
|
||||
}
|
||||
else {
|
||||
XPUSHs(sv_2mortal(newSViv(1))); /* true */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
blocksize(Crypt::AuthEnc::OCB self)
|
||||
CODE:
|
||||
{
|
||||
RETVAL = (&self->state)->block_len;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
658
inc/CryptX_BigInt_LTM.xs.inc
Normal file
658
inc/CryptX_BigInt_LTM.xs.inc
Normal file
@ -0,0 +1,658 @@
|
||||
MODULE = CryptX PACKAGE = Math::BigInt::LTM
|
||||
|
||||
|
||||
##############################################################################
|
||||
# _new()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_new(Class, SV *x)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
if ((SvUOK(x) || SvIOK(x)) && (sizeof(UV) <= sizeof(unsigned long) || SvUV(x) == (unsigned long)SvUV(x))) {
|
||||
mp_set_int(RETVAL, (unsigned long)SvUV(x));
|
||||
}
|
||||
else {
|
||||
mp_read_radix(RETVAL, SvPV_nolen(x), 10);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _from_bin()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_from_bin(Class, SV *x)
|
||||
PREINIT:
|
||||
char *str, *start;
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
str = SvPV_nolen(x);
|
||||
start = (strlen(str)>2 && str[0] == '0' && str[1] == 'b') ? str+2 : str;
|
||||
mp_read_radix(RETVAL, start, 2);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _from_hex()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_from_hex(Class, SV *x)
|
||||
PREINIT:
|
||||
char *str, *start;
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
str = SvPV_nolen(x);
|
||||
start = (strlen(str)>2 && str[0] == '0' && str[1] == 'x') ? str+2 : str;
|
||||
mp_read_radix(RETVAL, start, 16);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _from_oct()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_from_oct(Class, SV *x)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_read_radix(RETVAL, SvPV_nolen(x), 8);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _set() - set an already existing object to the given scalar value
|
||||
|
||||
void
|
||||
_set(Class, Math::BigInt::LTM n, SV *x)
|
||||
CODE:
|
||||
mp_set_int(n, (unsigned long)SvIV(x));
|
||||
|
||||
##############################################################################
|
||||
# _zero()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_zero(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_set_int(RETVAL, 0);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _one()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_one(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_set_int(RETVAL, 1);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _two()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_two(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_set_int(RETVAL, 2);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _ten()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_ten(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_set_int(RETVAL, 10);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _1ex()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_1ex(Class, int x)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_set_int(RETVAL, 10);
|
||||
mp_expt_d(RETVAL, x, RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# DESTROY() - free memory of a GMP number
|
||||
|
||||
void
|
||||
DESTROY(Math::BigInt::LTM n)
|
||||
PPCODE:
|
||||
if (n) {
|
||||
mp_clear(n);
|
||||
Safefree(n);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# _str() - return string so that atof() and atoi() can use it
|
||||
|
||||
SV *
|
||||
_str(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int len;
|
||||
char *buf;
|
||||
CODE:
|
||||
if (mp_iszero(n) == MP_YES) {
|
||||
RETVAL = newSVpv("0", 0);
|
||||
}
|
||||
else {
|
||||
len = mp_count_bits(n) / 3 + 3; /* decimal_size ~ (binary_size/3 + 1) +1 for sign +1 for NUL-byte */
|
||||
Newz(0, buf, len, char);
|
||||
mp_toradix_n(n, buf, 10, len);
|
||||
RETVAL = newSVpv(buf, 0);
|
||||
Safefree(buf);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _len() - return the length of the number in base 10 (costly)
|
||||
|
||||
int
|
||||
_len(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int len;
|
||||
char *buf;
|
||||
CODE:
|
||||
if (mp_iszero(n) == MP_YES) {
|
||||
RETVAL = 1;
|
||||
}
|
||||
else {
|
||||
len = mp_count_bits(n) / 3 + 3; /* decimal_size ~ (binary_size/3 + 1) +1 for sign +1 for NUL-byte */
|
||||
Newz(0, buf, len, char);
|
||||
mp_toradix_n(n, buf, 10, len);
|
||||
RETVAL = (int)strlen(buf);
|
||||
Safefree(buf);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _alen() - return the approx. length of the number in base 10 (fast)
|
||||
# _alen() might underestimate, but never overestimate the true value
|
||||
int
|
||||
_alen(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int bits;
|
||||
CODE:
|
||||
bits = mp_count_bits(n);
|
||||
/* alen = round(bits * log(2) / log(10)) */
|
||||
RETVAL = (bits < 5) ? 1 : (int)(bits * 0.301029995663 + 0.499999999999);
|
||||
/* less accurate approximation, but without floating-point calculations
|
||||
RETVAL = (bits < 5) ? 1 : bits / 4 + bits / 32 + bits / 64 + bits / 256;
|
||||
RETVAL = (bits < 5) ? 1 : bits / 4;
|
||||
*/
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _zeros() - return number of trailing zeros (in decimal form)
|
||||
|
||||
int
|
||||
_zeros(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int len;
|
||||
char *buf;
|
||||
CODE:
|
||||
if (mp_iszero(n) == MP_YES) {
|
||||
RETVAL = 0; /* '0' has no trailing zeros! */
|
||||
}
|
||||
else {
|
||||
len = mp_count_bits(n) / 3 + 3; /* decimal_size ~ (binary_size/3 + 1) +1 for sign +1 for NUL-byte */
|
||||
Newz(0, buf, len, char);
|
||||
mp_toradix_n(n, buf, 10, len);
|
||||
len = (int)strlen(buf);
|
||||
RETVAL = 0;
|
||||
while (len > 0) {
|
||||
if (buf[len-1] != '0') break;
|
||||
RETVAL++;
|
||||
len--;
|
||||
}
|
||||
Safefree(buf);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _as_hex() - return ref to hexadecimal string (prefixed with 0x)
|
||||
|
||||
SV *
|
||||
_as_hex(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int i, len;
|
||||
char *buf;
|
||||
CODE:
|
||||
len = mp_unsigned_bin_size(n) * 2 + 3;
|
||||
RETVAL = newSV(len);
|
||||
SvPOK_on(RETVAL);
|
||||
buf = SvPVX(RETVAL); /* get ptr to storage */
|
||||
*buf++ = '0'; *buf++ = 'x'; /* prepend '0x' */
|
||||
mp_tohex(n, buf);
|
||||
for (i=0; i<len && buf[i]>0; i++) buf[i] = toLOWER(buf[i]);
|
||||
SvCUR_set(RETVAL, strlen(buf)+2); /* set real length */
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _as_bin() - return ref to binary string (prefixed with 0b)
|
||||
|
||||
SV *
|
||||
_as_bin(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int len;
|
||||
char *buf;
|
||||
CODE:
|
||||
len = mp_unsigned_bin_size(n) * 8 + 3;
|
||||
RETVAL = newSV(len);
|
||||
SvPOK_on(RETVAL);
|
||||
buf = SvPVX(RETVAL); /* get ptr to storage */
|
||||
*buf++ = '0'; *buf++ = 'b'; /* prepend '0b' */
|
||||
mp_tobinary(n, buf);
|
||||
SvCUR_set(RETVAL, strlen(buf)+2); /* set real length */
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _as_oct() - return ref to octal string (prefixed with 0)
|
||||
|
||||
SV *
|
||||
_as_oct(Class, Math::BigInt::LTM n)
|
||||
PREINIT:
|
||||
int len;
|
||||
char *buf;
|
||||
CODE:
|
||||
len = mp_unsigned_bin_size(n) * 3 + 3;
|
||||
RETVAL = newSV(len);
|
||||
SvPOK_on(RETVAL);
|
||||
buf = SvPVX(RETVAL);
|
||||
*buf++ = '0'; /* prepend '0' */
|
||||
mp_tooctal(n, buf);
|
||||
SvCUR_set(RETVAL, strlen(buf)+1); /* set real length */
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _modpow() - ($n ** $exp) % $mod
|
||||
|
||||
Math::BigInt::LTM
|
||||
_modpow(Class, Math::BigInt::LTM n, Math::BigInt::LTM exp, Math::BigInt::LTM mod)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
if (mp_cmp_d(mod, 1) == MP_EQ) {
|
||||
mp_set_int(RETVAL, 0);
|
||||
}
|
||||
else {
|
||||
mp_exptmod(n, exp, mod, RETVAL);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _modinv() - compute the inverse of x % y
|
||||
|
||||
void
|
||||
_modinv(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PREINIT:
|
||||
int rc;
|
||||
SV* s;
|
||||
mp_int* RETVAL;
|
||||
PPCODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
rc = mp_invmod(x, y, RETVAL);
|
||||
EXTEND(SP, 2); /* we return two values */
|
||||
if (rc != MP_OKAY) {
|
||||
/* Inverse doesn't exist. Return both values undefined. */
|
||||
PUSHs(&PL_sv_undef);
|
||||
PUSHs(&PL_sv_undef);
|
||||
}
|
||||
else {
|
||||
/* Inverse exists. When the modulus to mp_invert() is positive,
|
||||
* the returned value is also positive. */
|
||||
PUSHs(sv_2mortal(sv_from_mpi(RETVAL)));
|
||||
s = sv_newmortal();
|
||||
sv_setpvn(s, "+", 1);
|
||||
PUSHs(s);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# _add() - add $y to $x in place
|
||||
|
||||
void
|
||||
_add(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_add(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _inc() - modify x inline by doing x++
|
||||
|
||||
void
|
||||
_inc(Class, Math::BigInt::LTM x)
|
||||
PPCODE:
|
||||
mp_add_d(x, 1, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _dec() - modify x inline by doing x--
|
||||
|
||||
void
|
||||
_dec(Class, Math::BigInt::LTM x)
|
||||
PPCODE:
|
||||
mp_sub_d(x, 1, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _sub() - $x - $y
|
||||
# $x is always larger than $y! So overflow/underflow can not happen here.
|
||||
|
||||
void
|
||||
_sub(Class, Math::BigInt::LTM x, Math::BigInt::LTM y, ...)
|
||||
PPCODE:
|
||||
if ( items == 4 && SvTRUE(ST(3)) ) {
|
||||
/* y -= x */
|
||||
mp_sub(x, y, y);
|
||||
XPUSHs(ST(2)); /* y */
|
||||
}
|
||||
else {
|
||||
/* x -= y */
|
||||
mp_sub(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# _rsft()
|
||||
|
||||
void
|
||||
_rsft(Class, Math::BigInt::LTM x, Math::BigInt::LTM y, unsigned long base_int)
|
||||
PREINIT:
|
||||
mp_int* BASE;
|
||||
PPCODE:
|
||||
Newz(0, BASE, 1, mp_int);
|
||||
mp_init_set_int(BASE, base_int);
|
||||
mp_expt_d(BASE, mp_get_long(y), BASE);
|
||||
mp_div(x, BASE, x, NULL);
|
||||
mp_clear(BASE);
|
||||
Safefree(BASE);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _lsft()
|
||||
|
||||
void
|
||||
_lsft(Class, Math::BigInt::LTM x, Math::BigInt::LTM y, unsigned long base_int)
|
||||
PREINIT:
|
||||
mp_int* BASE;
|
||||
PPCODE:
|
||||
Newz(0, BASE, 1, mp_int);
|
||||
mp_init_set_int(BASE, base_int);
|
||||
mp_expt_d(BASE, mp_get_long(y), BASE);
|
||||
mp_mul(x, BASE, x);
|
||||
mp_clear(BASE);
|
||||
Safefree(BASE);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _mul()
|
||||
|
||||
void
|
||||
_mul(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_mul(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _div(): x /= y or (x,rem) = x / y
|
||||
|
||||
void
|
||||
_div(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PREINIT:
|
||||
mp_int * rem;
|
||||
PPCODE:
|
||||
if (GIMME_V == G_ARRAY) {
|
||||
Newz(0, rem, 1, mp_int);
|
||||
mp_init(rem);
|
||||
mp_div(x, y, x, rem);
|
||||
EXTEND(SP, 2);
|
||||
PUSHs(ST(1)); /* x */
|
||||
PUSHs(sv_2mortal(sv_from_mpi(rem)));
|
||||
}
|
||||
else {
|
||||
mp_div(x, y, x, NULL);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# _mod() - x %= y
|
||||
|
||||
void
|
||||
_mod(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_mod(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _acmp() - cmp two numbers
|
||||
|
||||
int
|
||||
_acmp(Class, Math::BigInt::LTM m, Math::BigInt::LTM n)
|
||||
CODE:
|
||||
RETVAL = mp_cmp(m, n);
|
||||
if ( RETVAL < 0) RETVAL = -1;
|
||||
if ( RETVAL > 0) RETVAL = 1;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_zero()
|
||||
|
||||
int
|
||||
_is_zero(Class, Math::BigInt::LTM x)
|
||||
CODE:
|
||||
RETVAL = (mp_iszero(x) == MP_YES) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_one()
|
||||
|
||||
int
|
||||
_is_one(Class, Math::BigInt::LTM x)
|
||||
CODE:
|
||||
RETVAL = (mp_cmp_d(x, 1) == MP_EQ) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_two()
|
||||
|
||||
int
|
||||
_is_two(Class, Math::BigInt::LTM x)
|
||||
CODE:
|
||||
RETVAL = (mp_cmp_d(x, 2) == MP_EQ) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_ten()
|
||||
|
||||
int
|
||||
_is_ten(Class, Math::BigInt::LTM x)
|
||||
CODE:
|
||||
RETVAL = (mp_cmp_d(x, 10) == MP_EQ) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _pow() - x **= y
|
||||
|
||||
void
|
||||
_pow(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_expt_d(x, mp_get_long(y), x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _gcd() - gcd(m,n)
|
||||
|
||||
Math::BigInt::LTM
|
||||
_gcd(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_gcd(x, y, RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _and() - m &= n
|
||||
|
||||
void
|
||||
_and(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_and(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _xor() - m =^ n
|
||||
|
||||
void
|
||||
_xor(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_xor(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _or() - m =| n
|
||||
|
||||
void
|
||||
_or(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_or(x, y, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _copy()
|
||||
|
||||
Math::BigInt::LTM
|
||||
_copy(Class, Math::BigInt::LTM m)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, mp_int);
|
||||
mp_init(RETVAL);
|
||||
mp_copy(m, RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_odd() - test for number being odd
|
||||
|
||||
int
|
||||
_is_odd(Class, Math::BigInt::LTM n)
|
||||
CODE:
|
||||
RETVAL = (mp_isodd(n) == MP_YES) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _is_even() - test for number being even
|
||||
|
||||
int
|
||||
_is_even(Class, Math::BigInt::LTM n)
|
||||
CODE:
|
||||
RETVAL = (mp_iseven(n) == MP_YES || mp_iszero(n) == MP_YES) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
##############################################################################
|
||||
# _sqrt() - square root
|
||||
|
||||
void
|
||||
_sqrt(Class, Math::BigInt::LTM x)
|
||||
PPCODE:
|
||||
mp_sqrt(x, x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _root() - integer roots
|
||||
|
||||
void
|
||||
_root(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_n_root(x, mp_get_long(y), x);
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# _lcm() - least common multiple
|
||||
void
|
||||
_lcm(Class, Math::BigInt::LTM x, Math::BigInt::LTM y)
|
||||
PPCODE:
|
||||
mp_lcm(x, y, x) ;
|
||||
XPUSHs(ST(1)); /* x */
|
||||
|
||||
##############################################################################
|
||||
# Storable hooks
|
||||
|
||||
void
|
||||
STORABLE_thaw(blank_obj, cloning, serialized, ...)
|
||||
SV *blank_obj
|
||||
SV *cloning = NO_INIT
|
||||
SV *serialized
|
||||
PREINIT:
|
||||
SV *target;
|
||||
mp_int *mpi;
|
||||
PPCODE:
|
||||
PERL_UNUSED_VAR(cloning);
|
||||
if (SvROK(blank_obj) && sv_isa(blank_obj, "Math::BigInt::LTM")) {
|
||||
Newz(0, mpi, 1, mp_int);
|
||||
mp_init(mpi);
|
||||
mp_read_radix(mpi, SvPV_nolen(serialized), 10);
|
||||
target = SvRV(blank_obj);
|
||||
SvIV_set(target, PTR2IV(mpi));
|
||||
SvIOK_on(target);
|
||||
PUSHs(target);
|
||||
XSRETURN(1);
|
||||
}
|
||||
else
|
||||
croak("Bad object for Math::BigInt::LTM::STORABLE_thaw call");
|
||||
|
||||
SV *
|
||||
STORABLE_freeze(self, cloning = NULL)
|
||||
Math::BigInt::LTM self
|
||||
SV *cloning = NO_INIT
|
||||
PREINIT:
|
||||
unsigned long len;
|
||||
char *buf;
|
||||
CODE:
|
||||
PERL_UNUSED_VAR(cloning);
|
||||
if (mp_iszero(self) == MP_YES) {
|
||||
RETVAL = newSVpv("0", 0);
|
||||
}
|
||||
else {
|
||||
len = mp_count_bits(self) / 3 + 3; /* decimal_size ~ (binary_size/3 + 1) +1 for sign +1 for NUL-byte */
|
||||
Newz(0, buf, len, char);
|
||||
mp_toradix_n(self, buf, 10, len);
|
||||
RETVAL = newSVpv(buf, 0);
|
||||
Safefree(buf);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
70
inc/CryptX_Checksum_Adler32.xs.inc
Normal file
70
inc/CryptX_Checksum_Adler32.xs.inc
Normal file
@ -0,0 +1,70 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Checksum::Adler32
|
||||
|
||||
Crypt::Checksum::Adler32
|
||||
new(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, adler32_state);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
adler32_init(RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Checksum::Adler32 self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
void
|
||||
reset(Crypt::Checksum::Adler32 self)
|
||||
CODE:
|
||||
adler32_init(self);
|
||||
|
||||
Crypt::Checksum::Adler32
|
||||
clone(Crypt::Checksum::Adler32 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, adler32_state);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(self, RETVAL, 1, adler32_state);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
add(Crypt::Checksum::Adler32 self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN inlen;
|
||||
int i;
|
||||
unsigned char *in;
|
||||
for(i=1; i<items; i++) {
|
||||
in = (unsigned char *)SvPVbyte(ST(i), inlen);
|
||||
if (inlen>0) adler32_update(self, in, (unsigned long)inlen);
|
||||
}
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
SV *
|
||||
digest(Crypt::Checksum::Adler32 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char hash[4];
|
||||
adler32_finish(self, hash, 4);
|
||||
RETVAL = newSVpvn((char *) hash, 4);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexdigest(Crypt::Checksum::Adler32 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char hash[4];
|
||||
char hash_hex[4*2 + 1];
|
||||
adler32_finish(self, hash, 4);
|
||||
hash_hex[0] = '\0';
|
||||
for(i=0; i<4; i++) sprintf(&hash_hex[2*i], "%02x", hash[i]);
|
||||
RETVAL = newSVpvn(hash_hex, strlen(hash_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
70
inc/CryptX_Checksum_CRC32.xs.inc
Normal file
70
inc/CryptX_Checksum_CRC32.xs.inc
Normal file
@ -0,0 +1,70 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Checksum::CRC32
|
||||
|
||||
Crypt::Checksum::CRC32
|
||||
new(Class)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, crc32_state);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
crc32_init(RETVAL);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Checksum::CRC32 self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
void
|
||||
reset(Crypt::Checksum::CRC32 self)
|
||||
CODE:
|
||||
crc32_init(self);
|
||||
|
||||
Crypt::Checksum::CRC32
|
||||
clone(Crypt::Checksum::CRC32 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, crc32_state);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(self, RETVAL, 1, crc32_state);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
add(Crypt::Checksum::CRC32 self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN inlen;
|
||||
int i;
|
||||
unsigned char *in;
|
||||
for(i=1; i<items; i++) {
|
||||
in = (unsigned char *)SvPVbyte(ST(i), inlen);
|
||||
if (inlen>0) crc32_update(self, in, (unsigned long)inlen);
|
||||
}
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
SV *
|
||||
digest(Crypt::Checksum::CRC32 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char hash[4];
|
||||
crc32_finish(self, hash, 4);
|
||||
RETVAL = newSVpvn((char *) hash, 4);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexdigest(Crypt::Checksum::CRC32 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned char hash[4];
|
||||
char hash_hex[4*2 + 1];
|
||||
crc32_finish(self, hash, 4);
|
||||
hash_hex[0] = '\0';
|
||||
for(i=0; i<4; i++) sprintf(&hash_hex[2*i], "%02x", hash[i]);
|
||||
RETVAL = newSVpvn(hash_hex, strlen(hash_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
188
inc/CryptX_Cipher.xs.inc
Normal file
188
inc/CryptX_Cipher.xs.inc
Normal file
@ -0,0 +1,188 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Cipher
|
||||
|
||||
Crypt::Cipher
|
||||
_new(cipher_name, key, rounds=0)
|
||||
char * cipher_name
|
||||
SV * key
|
||||
int rounds
|
||||
CODE:
|
||||
{
|
||||
STRLEN key_len;
|
||||
unsigned char *key_data=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
if (!SvPOK (key)) croak("FATAL: key must be string scalar");
|
||||
key_data = (unsigned char *)SvPVbyte(key, key_len);
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
Newz(0, RETVAL, 1, struct cipher_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
RETVAL->id = id;
|
||||
RETVAL->desc = &cipher_descriptor[id];
|
||||
rv = RETVAL->desc->setup(key_data, (int)key_len, rounds, &RETVAL->skey);
|
||||
if(rv!=CRYPT_OK) croak("FATAL: cipher setup failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(self)
|
||||
Crypt::Cipher self
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_max_keysize(self, ...)
|
||||
Crypt::Cipher self
|
||||
CODE:
|
||||
RETVAL = self->desc->max_key_length;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_min_keysize(self, ...)
|
||||
Crypt::Cipher self
|
||||
CODE:
|
||||
RETVAL = self->desc->min_key_length;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_blocksize(self, ...)
|
||||
Crypt::Cipher self
|
||||
CODE:
|
||||
RETVAL = self->desc->block_length;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_default_rounds(self, ...)
|
||||
Crypt::Cipher self
|
||||
CODE:
|
||||
RETVAL = self->desc->default_rounds;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
encrypt(self, data)
|
||||
Crypt::Cipher self
|
||||
SV * data
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN len;
|
||||
void *plaintext = SvPVbyte(data, len);
|
||||
|
||||
if (len==0)
|
||||
RETVAL = newSVpvn("", 0);
|
||||
else if (len % self->desc->block_length)
|
||||
croak ("FATAL: sizeof(data) should be multiple of blocksize (%d)", self->desc->block_length);
|
||||
else {
|
||||
/* idea from Crypt::Rijndael */
|
||||
RETVAL = NEWSV(0, len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, len);
|
||||
rv = self->desc->ecb_encrypt((unsigned char *)plaintext, (unsigned char *)SvPV_nolen(RETVAL), &self->skey);
|
||||
if (rv!=CRYPT_OK) croak("FATAL: encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
decrypt(self, data)
|
||||
Crypt::Cipher self
|
||||
SV * data
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN len;
|
||||
void *ciphertext = SvPVbyte(data, len);
|
||||
|
||||
if (len==0)
|
||||
RETVAL = newSVpvn("", 0);
|
||||
else if (len % self->desc->block_length)
|
||||
croak ("FATAL: sizeof(data) should be multiple of blocksize (%d)", self->desc->block_length);
|
||||
else {
|
||||
/* idea from Crypt::Rijndael */
|
||||
RETVAL = NEWSV(0, len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, len);
|
||||
rv = self->desc->ecb_decrypt((unsigned char *)ciphertext, (unsigned char *)SvPV_nolen(RETVAL), &self->skey);
|
||||
if (rv!=CRYPT_OK) croak("FATAL: decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_block_length_by_name(cipher_name)
|
||||
char * cipher_name
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
rv = cipher_descriptor[id].block_length;
|
||||
if (!rv) XSRETURN_UNDEF;
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_min_key_length_by_name(cipher_name)
|
||||
char * cipher_name
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
rv = cipher_descriptor[id].min_key_length;
|
||||
if (!rv) XSRETURN_UNDEF;
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_max_key_length_by_name(cipher_name)
|
||||
char * cipher_name
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
rv = cipher_descriptor[id].max_key_length;
|
||||
if (!rv) XSRETURN_UNDEF;
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_default_rounds_by_name(cipher_name)
|
||||
char * cipher_name
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
rv = cipher_descriptor[id].default_rounds;
|
||||
if (!rv) XSRETURN_UNDEF;
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
169
inc/CryptX_Digest.xs.inc
Normal file
169
inc/CryptX_Digest.xs.inc
Normal file
@ -0,0 +1,169 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Digest
|
||||
|
||||
Crypt::Digest
|
||||
_new(digest_name)
|
||||
char * digest_name
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_hash(digest_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", digest_name);
|
||||
|
||||
Newz(0, RETVAL, 1, struct digest_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
RETVAL->id = id;
|
||||
RETVAL->desc = &hash_descriptor[id];
|
||||
rv = RETVAL->desc->init(&RETVAL->state);
|
||||
if(rv!=CRYPT_OK) croak("FATAL: digest setup failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
void
|
||||
reset(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
rv = self->desc->init(&self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest init failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
Crypt::Digest
|
||||
clone(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct digest_struct);
|
||||
Copy(&self->state, &RETVAL->state, 1, struct digest_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
add(Crypt::Digest self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN inlen;
|
||||
int rv, i;
|
||||
unsigned char *in;
|
||||
|
||||
for(i=1; i<items; i++) {
|
||||
in = (unsigned char *)SvPVbyte(ST(i), inlen);
|
||||
if (inlen>0) {
|
||||
rv = self->desc->process(&self->state, in, (unsigned long)inlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
SV *
|
||||
digest(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
{
|
||||
unsigned char hash[MAXBLOCKSIZE];
|
||||
int rv;
|
||||
|
||||
rv = self->desc->done(&self->state, hash);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char *) hash, self->desc->hashsize);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexdigest(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long i;
|
||||
unsigned char hash[MAXBLOCKSIZE];
|
||||
char hash_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
rv = self->desc->done(&self->state, hash);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv));
|
||||
|
||||
hash_hex[0] = '\0';
|
||||
for(i=0; i<self->desc->hashsize; i++)
|
||||
sprintf(&hash_hex[2*i], "%02x", hash[i]);
|
||||
RETVAL = newSVpvn(hash_hex, strlen(hash_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64digest(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
unsigned char hash[MAXBLOCKSIZE];
|
||||
char hash_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
rv = self->desc->done(&self->state, hash);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv));
|
||||
|
||||
outlen = sizeof(hash_base64);
|
||||
rv = base64_encode(hash, self->desc->hashsize, (unsigned char *)hash_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(hash_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64udigest(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
unsigned char hash[MAXBLOCKSIZE];
|
||||
char hash_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
rv = self->desc->done(&self->state, hash);
|
||||
if (rv != CRYPT_OK) croak("FATAL: digest done failed: %s", error_to_string(rv));
|
||||
|
||||
outlen = sizeof(hash_base64);
|
||||
rv = base64url_encode(hash, self->desc->hashsize, (unsigned char *)hash_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(hash_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_hashsize(self)
|
||||
Crypt::Digest self
|
||||
CODE:
|
||||
RETVAL = self->desc->hashsize;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_hashsize_by_name(digest_name)
|
||||
char * digest_name
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
|
||||
id = find_hash(digest_name);
|
||||
if(id==-1) croak("FATAL: find_digest failed for '%s'", digest_name);
|
||||
|
||||
rv = hash_descriptor[id].hashsize;
|
||||
if (!rv) croak("FATAL: invalid hashsize for '%s'", digest_name);;
|
||||
RETVAL = rv;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
74
inc/CryptX_Digest_SHAKE.xs.inc
Normal file
74
inc/CryptX_Digest_SHAKE.xs.inc
Normal file
@ -0,0 +1,74 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Digest::SHAKE
|
||||
|
||||
Crypt::Digest::SHAKE
|
||||
_new(int num)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
|
||||
Newz(0, RETVAL, 1, struct digest_shake_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
RETVAL->num = num;
|
||||
rv = sha3_shake_init(&RETVAL->state, RETVAL->num);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Digest::SHAKE self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
void
|
||||
reset(Crypt::Digest::SHAKE self)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
rv = sha3_shake_init(&self->state, self->num);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
Crypt::Digest::SHAKE
|
||||
clone(Crypt::Digest::SHAKE self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct digest_shake_struct);
|
||||
Copy(&self->state, &RETVAL->state, 1, struct digest_shake_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
add(Crypt::Digest::SHAKE self, ...)
|
||||
PPCODE:
|
||||
{
|
||||
STRLEN inlen;
|
||||
int rv, i;
|
||||
unsigned char *in;
|
||||
|
||||
for(i=1; i<items; i++) {
|
||||
in = (unsigned char *)SvPVbyte(ST(i), inlen);
|
||||
if (inlen>0) {
|
||||
rv = sha3_shake_process(&self->state, in, (unsigned long)inlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sha3_shake_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
SV *
|
||||
done(Crypt::Digest::SHAKE self, STRLEN out_len)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *out_data;
|
||||
|
||||
RETVAL = NEWSV(0, out_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, out_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = sha3_shake_done(&self->state, out_data, out_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sha3_shake_done failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
181
inc/CryptX_KeyDerivation.xs.inc
Normal file
181
inc/CryptX_KeyDerivation.xs.inc
Normal file
@ -0,0 +1,181 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::KeyDerivation
|
||||
|
||||
SV *
|
||||
_pkcs_5_alg1(SV * password, SV * salt, int iteration_count, char * hash_name, int len)
|
||||
CODE:
|
||||
{
|
||||
/*
|
||||
int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
|
||||
const unsigned char *salt,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
*/
|
||||
int rv, id;
|
||||
unsigned long output_len;
|
||||
unsigned char *output;
|
||||
unsigned char *password_ptr=NULL;
|
||||
STRLEN password_len=0;
|
||||
unsigned char *salt_ptr=NULL;
|
||||
STRLEN salt_len=0;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
password_ptr = (unsigned char *)SvPVbyte(password, password_len);
|
||||
salt_ptr = (unsigned char *)SvPVbyte(salt, salt_len);
|
||||
if (salt_len < 8) croak("FATAL: salt_len has to be 8");
|
||||
|
||||
output_len = len;
|
||||
Newz(0, output, output_len, unsigned char);
|
||||
if (!output) croak("FATAL: Newz failed [%ld]", output_len);
|
||||
|
||||
rv = pkcs_5_alg1(password_ptr, (unsigned long)password_len, salt_ptr, iteration_count, id, output, &output_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pkcs_5_alg1 process failed: %s", error_to_string(rv));
|
||||
|
||||
RETVAL = newSVpvn((char *)output, output_len);
|
||||
Safefree(output);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_pkcs_5_alg2(SV * password, SV * salt, int iteration_count, char * hash_name, int len)
|
||||
CODE:
|
||||
{
|
||||
/*
|
||||
int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
|
||||
const unsigned char *salt, unsigned long salt_len,
|
||||
int iteration_count, int hash_idx,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
*/
|
||||
int rv, id;
|
||||
unsigned long output_len;
|
||||
unsigned char *output;
|
||||
unsigned char *password_ptr=NULL;
|
||||
STRLEN password_len=0;
|
||||
unsigned char *salt_ptr=NULL;
|
||||
STRLEN salt_len=0;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
password_ptr = (unsigned char *)SvPVbyte(password, password_len);
|
||||
salt_ptr = (unsigned char *)SvPVbyte(salt, salt_len);
|
||||
|
||||
output_len = len;
|
||||
Newz(0, output, output_len, unsigned char);
|
||||
if (!output) croak("FATAL: Newz failed [%ld]", output_len);
|
||||
|
||||
rv = pkcs_5_alg2(password_ptr, (unsigned long)password_len, salt_ptr, (unsigned long)salt_len, iteration_count, id, output, &output_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pkcs_5_alg2 process failed: %s", error_to_string(rv));
|
||||
|
||||
RETVAL = newSVpvn((char *)output, output_len);
|
||||
Safefree(output);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_hkdf_extract(char * hash_name, SV * salt, SV * in)
|
||||
CODE:
|
||||
{
|
||||
/*
|
||||
int hkdf_extract(int hash_idx, const unsigned char *salt, unsigned long saltlen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
*/
|
||||
int rv, id;
|
||||
unsigned char output[MAXBLOCKSIZE];
|
||||
unsigned long output_len;
|
||||
unsigned char *in_ptr=NULL;
|
||||
STRLEN in_len=0;
|
||||
unsigned char *salt_ptr=NULL;
|
||||
STRLEN salt_len=0;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
in_ptr = (unsigned char *)SvPVbyte(in, in_len);
|
||||
salt_ptr = (unsigned char *)SvPVbyte(salt, salt_len);
|
||||
|
||||
output_len = sizeof(output);
|
||||
rv = hkdf_extract(id, salt_ptr, (unsigned long)salt_len, in_ptr, (unsigned long)in_len, output, &output_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hkdf_extract process failed: %s", error_to_string(rv));
|
||||
|
||||
RETVAL = newSVpvn((char *)output, output_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_hkdf_expand(char * hash_name, SV * info, SV * in, unsigned long output_len)
|
||||
CODE:
|
||||
{
|
||||
/*
|
||||
int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long outlen)
|
||||
*/
|
||||
int rv, id;
|
||||
unsigned char *output;
|
||||
unsigned char *in_ptr=NULL;
|
||||
STRLEN in_len=0;
|
||||
unsigned char *info_ptr=NULL;
|
||||
STRLEN info_len=0;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
in_ptr = (unsigned char *)SvPVbyte(in, in_len);
|
||||
info_ptr = (unsigned char *)SvPVbyte(info, info_len);
|
||||
|
||||
Newz(0, output, output_len, unsigned char);
|
||||
if (!output) croak("FATAL: Newz failed [%ld]", output_len);
|
||||
|
||||
rv = hkdf_expand(id, info_ptr, (unsigned long)info_len, in_ptr, (unsigned long)in_len, output, output_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hkdf_expand process failed: %s", error_to_string(rv));
|
||||
|
||||
RETVAL = newSVpvn((char *)output, output_len);
|
||||
Safefree(output);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_hkdf(char * hash_name, SV * salt, SV * info, SV * in, unsigned long output_len)
|
||||
CODE:
|
||||
{
|
||||
/*
|
||||
int hkdf(int hash_idx, const unsigned char *salt, unsigned long saltlen,
|
||||
const unsigned char *info, unsigned long infolen,
|
||||
const unsigned char *in, unsigned long inlen,
|
||||
unsigned char *out, unsigned long outlen)
|
||||
*/
|
||||
int rv, id;
|
||||
unsigned char *output;
|
||||
unsigned char *in_ptr=NULL;
|
||||
STRLEN in_len=0;
|
||||
unsigned char *info_ptr=NULL;
|
||||
STRLEN info_len=0;
|
||||
unsigned char *salt_ptr=NULL;
|
||||
STRLEN salt_len=0;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
in_ptr = (unsigned char *)SvPVbyte(in, in_len);
|
||||
info_ptr = (unsigned char *)SvPVbyte(info, info_len);
|
||||
salt_ptr = (unsigned char *)SvPVbyte(salt, salt_len);
|
||||
|
||||
Newz(0, output, output_len, unsigned char);
|
||||
if (!output) croak("FATAL: Newz failed [%ld]", output_len);
|
||||
|
||||
rv = hkdf(id, salt_ptr, (unsigned long)salt_len, info_ptr, (unsigned long)info_len, in_ptr, (unsigned long)in_len, output, output_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hkdf_expand process failed: %s", error_to_string(rv));
|
||||
|
||||
RETVAL = newSVpvn((char *)output, output_len);
|
||||
Safefree(output);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
130
inc/CryptX_Mac_BLAKE2b.xs.inc
Normal file
130
inc/CryptX_Mac_BLAKE2b.xs.inc
Normal file
@ -0,0 +1,130 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::BLAKE2b
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::BLAKE2b
|
||||
_new(int size, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct blake2b_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = blake2bmac_init(&RETVAL->state, size, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2b_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::BLAKE2b
|
||||
clone(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct blake2b_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct blake2b_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::BLAKE2b self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = blake2bmac_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2b_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2bmac_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2bmac_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2bmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2bmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2bmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2bmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::BLAKE2b self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2bmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2bmac_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
130
inc/CryptX_Mac_BLAKE2s.xs.inc
Normal file
130
inc/CryptX_Mac_BLAKE2s.xs.inc
Normal file
@ -0,0 +1,130 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::BLAKE2s
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::BLAKE2s
|
||||
_new(int size, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct blake2s_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = blake2smac_init(&RETVAL->state, size, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2s_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::BLAKE2s
|
||||
clone(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct blake2s_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct blake2s_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::BLAKE2s self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = blake2smac_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2s_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2smac_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2smac_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2smac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2smac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2smac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2smac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::BLAKE2s self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = blake2smac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: blake2smac_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
134
inc/CryptX_Mac_F9.xs.inc
Normal file
134
inc/CryptX_Mac_F9.xs.inc
Normal file
@ -0,0 +1,134 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::F9
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::F9
|
||||
_new(char * cipher_name, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct f9_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = f9_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::F9
|
||||
clone(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct f9_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct f9_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::F9 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = f9_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = f9_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = f9_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = f9_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::F9 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = f9_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
134
inc/CryptX_Mac_HMAC.xs.inc
Normal file
134
inc/CryptX_Mac_HMAC.xs.inc
Normal file
@ -0,0 +1,134 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::HMAC
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::HMAC
|
||||
_new(char * hash_name, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_hash(hash_name);
|
||||
if(id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct hmac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = hmac_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::HMAC
|
||||
clone(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct hmac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct hmac_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::HMAC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = hmac_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = hmac_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = hmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = hmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::HMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = hmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
134
inc/CryptX_Mac_OMAC.xs.inc
Normal file
134
inc/CryptX_Mac_OMAC.xs.inc
Normal file
@ -0,0 +1,134 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::OMAC
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::OMAC
|
||||
_new(char * cipher_name, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct omac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = omac_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::OMAC
|
||||
clone(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct omac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct omac_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::OMAC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = omac_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = omac_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = omac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = omac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::OMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = omac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: omac_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
134
inc/CryptX_Mac_PMAC.xs.inc
Normal file
134
inc/CryptX_Mac_PMAC.xs.inc
Normal file
@ -0,0 +1,134 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::PMAC
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::PMAC
|
||||
_new(char * cipher_name, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct pmac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = pmac_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::PMAC
|
||||
clone(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct pmac_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct pmac_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::PMAC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = pmac_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = pmac_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = pmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = pmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::PMAC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = pmac_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pmac_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
130
inc/CryptX_Mac_Pelican.xs.inc
Normal file
130
inc/CryptX_Mac_Pelican.xs.inc
Normal file
@ -0,0 +1,130 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::Pelican
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::Pelican
|
||||
_new(SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct pelican_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = pelican_init(&RETVAL->state, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::Pelican
|
||||
clone(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct pelican_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct pelican_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::Pelican self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = pelican_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = 16;
|
||||
rv = pelican_done(&self->state, (unsigned char*)mac);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = 16;
|
||||
rv = pelican_done(&self->state, mac);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = 16;
|
||||
rv = pelican_done(&self->state, mac);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::Pelican self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = 16;
|
||||
rv = pelican_done(&self->state, mac);
|
||||
if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
130
inc/CryptX_Mac_Poly1305.xs.inc
Normal file
130
inc/CryptX_Mac_Poly1305.xs.inc
Normal file
@ -0,0 +1,130 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::Poly1305
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::Poly1305
|
||||
_new(SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct poly1305_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = poly1305_init(&RETVAL->state, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::Poly1305
|
||||
clone(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct poly1305_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct poly1305_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::Poly1305 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = poly1305_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = poly1305_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = poly1305_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = poly1305_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::Poly1305 self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = poly1305_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
134
inc/CryptX_Mac_XCBC.xs.inc
Normal file
134
inc/CryptX_Mac_XCBC.xs.inc
Normal file
@ -0,0 +1,134 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mac::XCBC
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mac::XCBC
|
||||
_new(char * cipher_name, SV * key)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
int rv;
|
||||
int id;
|
||||
|
||||
id = find_cipher(cipher_name);
|
||||
if(id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct xcbc_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = xcbc_init(&RETVAL->state, id, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_init failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Mac::XCBC
|
||||
clone(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct xcbc_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct xcbc_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_add_single(Crypt::Mac::XCBC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len>0) {
|
||||
rv = xcbc_process(&self->state, in_data, (unsigned long)in_data_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
|
||||
SV *
|
||||
mac(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
{
|
||||
char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = xcbc_done(&self->state, (unsigned char*)mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac, mac_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64mac(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = xcbc_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
b64umac(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len;
|
||||
int rv;
|
||||
unsigned long outlen;
|
||||
char mac_base64[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = xcbc_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
|
||||
outlen = sizeof(mac_base64);
|
||||
rv = base64url_encode(mac, mac_len, (unsigned char*)mac_base64, &outlen);
|
||||
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn(mac_base64, outlen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
hexmac(Crypt::Mac::XCBC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char mac[MAXBLOCKSIZE];
|
||||
unsigned long mac_len, i;
|
||||
int rv;
|
||||
char mac_hex[MAXBLOCKSIZE*2 + 1];
|
||||
|
||||
mac_len = sizeof(mac);
|
||||
rv = xcbc_done(&self->state, mac, &mac_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
|
||||
mac_hex[0] = '\0';
|
||||
for(i=0; i<mac_len; i++)
|
||||
sprintf(&mac_hex[2*i], "%02x", mac[i]);
|
||||
RETVAL = newSVpvn(mac_hex, strlen(mac_hex));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
290
inc/CryptX_Mode_CBC.xs.inc
Normal file
290
inc/CryptX_Mode_CBC.xs.inc
Normal file
@ -0,0 +1,290 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mode::CBC
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mode::CBC
|
||||
_new(char * cipher_name, int padding=1, int rounds=0)
|
||||
CODE:
|
||||
{
|
||||
Newz(0, RETVAL, 1, struct cbc_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->padding_mode = padding;
|
||||
RETVAL->padlen = 0;
|
||||
RETVAL->direction = 0;
|
||||
RETVAL->cipher_rounds = rounds;
|
||||
RETVAL->cipher_id = find_cipher(cipher_name);
|
||||
if(RETVAL->cipher_id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mode::CBC self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_get_dir(Crypt::Mode::CBC self)
|
||||
CODE:
|
||||
RETVAL = self->direction;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_start(Crypt::Mode::CBC self, int dir, SV * key, SV * iv)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
STRLEN i_len=0;
|
||||
unsigned char *i=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
if (!SvPOK(iv)) croak("FATAL: iv must be string/buffer scalar");
|
||||
i = (unsigned char *) SvPVbyte(iv, i_len);
|
||||
if (i_len != (STRLEN)cipher_descriptor[self->cipher_id].block_length) {
|
||||
croak ("FATAL: sizeof(iv) should be equal to blocksize (%d)", cipher_descriptor[self->cipher_id].block_length);
|
||||
}
|
||||
rv = cbc_start(self->cipher_id, i, k, (unsigned long)k_len, self->cipher_rounds, &self->state);
|
||||
if (rv != CRYPT_OK) {
|
||||
croak("FATAL: cbc_start failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
self->direction = dir;
|
||||
self->padlen = 0;
|
||||
}
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::Mode::CBC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, has_tmp_block, blen;
|
||||
unsigned long i;
|
||||
|
||||
STRLEN in_data_len, in_data_start;
|
||||
unsigned char *in_data, *out_data, tmp_block[MAXBLOCKSIZE];
|
||||
|
||||
if (self->direction != 1) croak("FATAL: encrypt error, call start_encrypt first (%d)", self->direction);
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
in_data_start = 0;
|
||||
has_tmp_block = 0;
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
if(self->padlen > 0) {
|
||||
i = (blen - self->padlen);
|
||||
if (in_data_len >= i) { /* enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, i, unsigned char);
|
||||
in_data_len -= i;
|
||||
in_data_start = i;
|
||||
rv = cbc_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_encrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
}
|
||||
else { /* not enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, in_data_len, unsigned char);
|
||||
self->padlen += (int)in_data_len;
|
||||
in_data_len = 0;
|
||||
}
|
||||
} /* padlen > 0 */
|
||||
|
||||
i = (unsigned long)(in_data_len % blen);
|
||||
if (in_data_len>0 && i>0) { /* save tail of data into pad */
|
||||
Copy(in_data+in_data_start+in_data_len-i, self->pad, i, unsigned char);
|
||||
self->padlen = i;
|
||||
in_data_len -= i;
|
||||
}
|
||||
|
||||
if (in_data_len>0) {
|
||||
i = (unsigned long)(has_tmp_block ? in_data_len + blen : in_data_len);
|
||||
RETVAL = NEWSV(0, i);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, i);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (has_tmp_block) {
|
||||
Copy(tmp_block, out_data, blen, unsigned char);
|
||||
out_data += blen;
|
||||
}
|
||||
rv = cbc_encrypt(in_data+in_data_start, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_encrypt failed: %s", error_to_string(rv));
|
||||
} /* in_data_len>0 */
|
||||
else if (has_tmp_block) {
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish_enc(Crypt::Mode::CBC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char tmp_block[MAXBLOCKSIZE];
|
||||
int rv, blen, i, j;
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
if (self->padlen<0 || self->padlen>=blen) croak("FATAL: invalid padlen");
|
||||
|
||||
if(self->padding_mode == 1) { /* pkcs5|7 padding */
|
||||
i = blen - self->padlen;
|
||||
if (i == 0) i = blen;
|
||||
for(j=self->padlen; j<blen; j++) self->pad[j] = (unsigned char)i;
|
||||
rv = cbc_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if(self->padding_mode == 2) { /* oneandzeroes padding */
|
||||
self->pad[self->padlen] = 0x80;
|
||||
for(j=self->padlen+1; j<blen; j++) self->pad[j] = 0;
|
||||
rv = cbc_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
if (self->padlen>0) croak("FATAL: cbc_encrypt, input data length not multiple of %d", blen);
|
||||
blen = 0;
|
||||
}
|
||||
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::Mode::CBC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, has_tmp_block, blen;
|
||||
unsigned long i;
|
||||
STRLEN in_data_len, in_data_start;
|
||||
unsigned char *in_data, *out_data, tmp_block[MAXBLOCKSIZE];
|
||||
|
||||
if (self->direction != -1) croak("FATAL: decrypt error, call start_decryt first (%d)", self->direction);
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
in_data_start = 0;
|
||||
has_tmp_block = 0;
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
|
||||
if(self->padlen == blen) {
|
||||
rv = cbc_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_decrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
} /* padlen == blen */
|
||||
else if(self->padlen > 0) {
|
||||
i = (blen - self->padlen); /* remaining bytes in padding buffer */
|
||||
if (in_data_len >= i) { /* enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, i, unsigned char);
|
||||
self->padlen += i;
|
||||
in_data_len -= i;
|
||||
in_data_start = i;
|
||||
if (in_data_len>0 || self->padding_mode == 0) {
|
||||
rv = cbc_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_decrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
}
|
||||
}
|
||||
else { /* not enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, in_data_len, unsigned char);
|
||||
self->padlen += (int)in_data_len;
|
||||
in_data_len = 0;
|
||||
}
|
||||
} /* padlen > 0 */
|
||||
|
||||
/* here: a/ padlen==1..16 && in_data_len==0; b/ padlen==0 && in_data_len>0 */
|
||||
if (in_data_len>0) {
|
||||
i = (unsigned long)(in_data_len % blen);
|
||||
if (i>0) { /* save tail of data into pad */
|
||||
Copy(in_data+in_data_start+in_data_len-i, self->pad, i, unsigned char);
|
||||
self->padlen = i;
|
||||
in_data_len -= i;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_data_len>0) {
|
||||
if(self->padlen == 0 && self->padding_mode !=0) {
|
||||
/* in case of padding keep full pad if no more data */
|
||||
Copy(in_data+in_data_start+in_data_len-blen, self->pad, blen, unsigned char);
|
||||
self->padlen = blen;
|
||||
in_data_len -= blen;
|
||||
}
|
||||
i = (unsigned long)(has_tmp_block ? in_data_len + blen : in_data_len);
|
||||
if (i == 0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, i);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, i);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
if (has_tmp_block) {
|
||||
Copy(tmp_block, out_data, blen, unsigned char);
|
||||
out_data += blen;
|
||||
}
|
||||
rv = cbc_decrypt(in_data+in_data_start, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
} /* in_data_len>0 */
|
||||
else if (has_tmp_block) {
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish_dec(Crypt::Mode::CBC self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char tmp_block[MAXBLOCKSIZE];
|
||||
unsigned char i;
|
||||
int rv, rv_len, blen;
|
||||
|
||||
rv_len = 0;
|
||||
if (self->padlen > 0) {
|
||||
blen = (&self->state)->blocklen;
|
||||
if (self->padlen != blen) croak("FATAL: cipher text length has to be multiple of %d (%d)", blen, self->padlen);
|
||||
rv = cbc_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cbc_decrypt failed: %s", error_to_string(rv));
|
||||
if(self->padding_mode == 0) { /* no padding */
|
||||
rv_len = blen;
|
||||
}
|
||||
else if(self->padding_mode == 1) { /* pkcs5|7 padding */
|
||||
i = tmp_block[blen-1];
|
||||
rv_len = blen - (i>blen ? blen : i);
|
||||
}
|
||||
else if(self->padding_mode == 2) { /* oneandzeroes padding */
|
||||
rv_len = blen;
|
||||
while ((unsigned char)tmp_block[rv_len-1] == 0x00) rv_len--;
|
||||
if ((unsigned char)tmp_block[rv_len-1] == 0x80) rv_len--;
|
||||
if (rv_len<0) rv_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn((char*)tmp_block, rv_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
98
inc/CryptX_Mode_CFB.xs.inc
Normal file
98
inc/CryptX_Mode_CFB.xs.inc
Normal file
@ -0,0 +1,98 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mode::CFB
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mode::CFB
|
||||
_new(char * cipher_name, int rounds=0)
|
||||
CODE:
|
||||
{
|
||||
Newz(0, RETVAL, 1, struct cfb_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->direction = 0;
|
||||
RETVAL->cipher_rounds = rounds;
|
||||
RETVAL->cipher_id = find_cipher(cipher_name);
|
||||
if(RETVAL->cipher_id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mode::CFB self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_get_dir(Crypt::Mode::CFB self)
|
||||
CODE:
|
||||
RETVAL = self->direction;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_start(Crypt::Mode::CFB self, int dir, SV * key, SV * iv)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
STRLEN i_len=0;
|
||||
unsigned char *i=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
if (!SvPOK(iv)) croak("FATAL: iv must be string/buffer scalar");
|
||||
i = (unsigned char *) SvPVbyte(iv, i_len);
|
||||
if (i_len != (STRLEN)cipher_descriptor[self->cipher_id].block_length) {
|
||||
croak ("FATAL: sizeof(iv) should be equal to blocksize (%d)", cipher_descriptor[self->cipher_id].block_length);
|
||||
}
|
||||
|
||||
rv = cfb_start(self->cipher_id, i, k, (int)k_len, self->cipher_rounds, &self->state);
|
||||
if (rv != CRYPT_OK) {
|
||||
croak("FATAL: cfb_start failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
self->direction = dir;
|
||||
}
|
||||
|
||||
SV *
|
||||
_crypt(Crypt::Mode::CFB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (self->direction == 1) {
|
||||
rv = cfb_encrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cfb_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if (self->direction == -1) {
|
||||
rv = cfb_decrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: cfb_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
croak("FATAL: cfb_crypt failed: call start_encrypt or start_decrypt first");
|
||||
}
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish(Crypt::Mode::CFB self)
|
||||
CODE:
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn("", 0);
|
||||
OUTPUT:
|
||||
RETVAL
|
103
inc/CryptX_Mode_CTR.xs.inc
Normal file
103
inc/CryptX_Mode_CTR.xs.inc
Normal file
@ -0,0 +1,103 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mode::CTR
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mode::CTR
|
||||
_new(char * cipher_name, int ctr_mode=0, int ctr_width=0, int rounds=0)
|
||||
CODE:
|
||||
{
|
||||
Newz(0, RETVAL, 1, struct ctr_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->direction = 0;
|
||||
RETVAL->cipher_rounds = rounds;
|
||||
RETVAL->cipher_id = find_cipher(cipher_name);
|
||||
if(RETVAL->cipher_id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
if (ctr_mode == 0) RETVAL->ctr_mode_param = CTR_COUNTER_LITTLE_ENDIAN;
|
||||
if (ctr_mode == 1) RETVAL->ctr_mode_param = CTR_COUNTER_BIG_ENDIAN;
|
||||
if (ctr_mode == 2) RETVAL->ctr_mode_param = CTR_COUNTER_LITTLE_ENDIAN|LTC_CTR_RFC3686;
|
||||
if (ctr_mode == 3) RETVAL->ctr_mode_param = CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686;
|
||||
if (ctr_width > 0 && ctr_width <= cipher_descriptor[RETVAL->cipher_id].block_length) RETVAL->ctr_mode_param |= ctr_width;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mode::CTR self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_get_dir(Crypt::Mode::CTR self)
|
||||
CODE:
|
||||
RETVAL = self->direction;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_start(Crypt::Mode::CTR self, int dir, SV * key, SV * iv)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
STRLEN i_len=0;
|
||||
unsigned char *i=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
if (!SvPOK(iv)) croak("FATAL: iv must be string/buffer scalar");
|
||||
i = (unsigned char *) SvPVbyte(iv, i_len);
|
||||
if (i_len != (STRLEN)cipher_descriptor[self->cipher_id].block_length) {
|
||||
croak ("FATAL: sizeof(iv) should be equal to blocksize (%d)", cipher_descriptor[self->cipher_id].block_length);
|
||||
}
|
||||
|
||||
rv = ctr_start(self->cipher_id, i, k, (int)k_len, self->cipher_rounds, self->ctr_mode_param, &self->state);
|
||||
if (rv != CRYPT_OK) {
|
||||
croak("FATAL: ctr_start failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
self->direction = dir;
|
||||
}
|
||||
|
||||
SV *
|
||||
_crypt(Crypt::Mode::CTR self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (self->direction == 1) {
|
||||
rv = ctr_encrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ctr_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if (self->direction == -1) {
|
||||
rv = ctr_decrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ctr_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
croak("FATAL: ctr_crypt failed: call start_encrypt or start_decrypt first");
|
||||
}
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish(Crypt::Mode::CTR self)
|
||||
CODE:
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn("", 0);
|
||||
OUTPUT:
|
||||
RETVAL
|
283
inc/CryptX_Mode_ECB.xs.inc
Normal file
283
inc/CryptX_Mode_ECB.xs.inc
Normal file
@ -0,0 +1,283 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mode::ECB
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mode::ECB
|
||||
_new(char * cipher_name, int padding=1, int rounds=0)
|
||||
CODE:
|
||||
{
|
||||
Newz(0, RETVAL, 1, struct ecb_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->padding_mode = padding;
|
||||
RETVAL->padlen = 0;
|
||||
RETVAL->direction = 0;
|
||||
RETVAL->cipher_rounds = rounds;
|
||||
RETVAL->cipher_id = find_cipher(cipher_name);
|
||||
if(RETVAL->cipher_id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mode::ECB self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_get_dir(Crypt::Mode::ECB self)
|
||||
CODE:
|
||||
RETVAL = self->direction;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_start(Crypt::Mode::ECB self, int dir, SV * key)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
rv = ecb_start(self->cipher_id, k, (unsigned long)k_len, self->cipher_rounds, &self->state);
|
||||
if (rv != CRYPT_OK) {
|
||||
croak("FATAL: ecb_start failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
self->direction = dir;
|
||||
self->padlen = 0;
|
||||
}
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::Mode::ECB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, has_tmp_block, blen;
|
||||
unsigned long i;
|
||||
|
||||
STRLEN in_data_len, in_data_start;
|
||||
unsigned char *in_data, *out_data, tmp_block[MAXBLOCKSIZE];
|
||||
|
||||
if (self->direction != 1) croak("FATAL: encrypt error, call start_encrypt first (%d)", self->direction);
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
in_data_start = 0;
|
||||
has_tmp_block = 0;
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
if(self->padlen > 0) {
|
||||
i = (blen - self->padlen);
|
||||
if (in_data_len >= i) { /* enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, i, unsigned char);
|
||||
in_data_len -= i;
|
||||
in_data_start = i;
|
||||
rv = ecb_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_encrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
}
|
||||
else { /* not enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, in_data_len, unsigned char);
|
||||
self->padlen += (int)in_data_len;
|
||||
in_data_len = 0;
|
||||
}
|
||||
} /* padlen > 0 */
|
||||
|
||||
i = (unsigned long)(in_data_len % blen);
|
||||
if (in_data_len>0 && i>0) { /* save tail of data into pad */
|
||||
Copy(in_data+in_data_start+in_data_len-i, self->pad, i, unsigned char);
|
||||
self->padlen = i;
|
||||
in_data_len -= i;
|
||||
}
|
||||
|
||||
if (in_data_len>0) {
|
||||
i = (unsigned long)(has_tmp_block ? in_data_len + blen : in_data_len);
|
||||
RETVAL = NEWSV(0, i);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, i);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (has_tmp_block) {
|
||||
Copy(tmp_block, out_data, blen, unsigned char);
|
||||
out_data += blen;
|
||||
}
|
||||
rv = ecb_encrypt(in_data+in_data_start, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_encrypt failed: %s", error_to_string(rv));
|
||||
} /* in_data_len>0 */
|
||||
else if (has_tmp_block) {
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish_enc(Crypt::Mode::ECB self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char tmp_block[MAXBLOCKSIZE];
|
||||
int rv, blen, i, j;
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
if (self->padlen<0 || self->padlen>=blen) croak("FATAL: invalid padlen");
|
||||
|
||||
if(self->padding_mode == 1) { /* pkcs5|7 padding */
|
||||
i = blen - self->padlen;
|
||||
if (i == 0) i = blen;
|
||||
for(j=self->padlen; j<blen; j++) self->pad[j] = (unsigned char)i;
|
||||
rv = ecb_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if(self->padding_mode == 2) { /* oneandzeroes padding */
|
||||
self->pad[self->padlen] = 0x80;
|
||||
for(j=self->padlen+1; j<blen; j++) self->pad[j] = 0;
|
||||
rv = ecb_encrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
if (self->padlen>0) croak("FATAL: ecb_encrypt, input data length not multiple of %d", blen);
|
||||
blen = 0;
|
||||
}
|
||||
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::Mode::ECB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, has_tmp_block, blen;
|
||||
unsigned long i;
|
||||
STRLEN in_data_len, in_data_start;
|
||||
unsigned char *in_data, *out_data, tmp_block[MAXBLOCKSIZE];
|
||||
|
||||
if (self->direction != -1) croak("FATAL: decrypt error, call start_decryt first (%d)", self->direction);
|
||||
|
||||
blen = (&self->state)->blocklen;
|
||||
in_data_start = 0;
|
||||
has_tmp_block = 0;
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
|
||||
if(self->padlen == blen) {
|
||||
rv = ecb_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_decrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
} /* padlen == blen */
|
||||
else if(self->padlen > 0) {
|
||||
i = (blen - self->padlen); /* remaining bytes in padding buffer */
|
||||
if (in_data_len >= i) { /* enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, i, unsigned char);
|
||||
self->padlen += i;
|
||||
in_data_len -= i;
|
||||
in_data_start = i;
|
||||
if (in_data_len>0 || self->padding_mode == 0) {
|
||||
rv = ecb_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_decrypt failed: %s", error_to_string(rv));
|
||||
self->padlen = 0;
|
||||
has_tmp_block = 1;
|
||||
}
|
||||
}
|
||||
else { /* not enough data to fill pad */
|
||||
Copy(in_data, self->pad+self->padlen, in_data_len, unsigned char);
|
||||
self->padlen += (int)in_data_len;
|
||||
in_data_len = 0;
|
||||
}
|
||||
} /* padlen > 0 */
|
||||
|
||||
/* here: a/ padlen==1..16 && in_data_len==0; b/ padlen==0 && in_data_len>0 */
|
||||
if (in_data_len>0) {
|
||||
i = (unsigned long)(in_data_len % blen);
|
||||
if (i>0) { /* save tail of data into pad */
|
||||
Copy(in_data+in_data_start+in_data_len-i, self->pad, i, unsigned char);
|
||||
self->padlen = i;
|
||||
in_data_len -= i;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_data_len>0) {
|
||||
if(self->padlen == 0 && self->padding_mode !=0) {
|
||||
/* in case of padding keep full pad if no more data */
|
||||
Copy(in_data+in_data_start+in_data_len-blen, self->pad, blen, unsigned char);
|
||||
self->padlen = blen;
|
||||
in_data_len -= blen;
|
||||
}
|
||||
i = (unsigned long)(has_tmp_block ? in_data_len + blen : in_data_len);
|
||||
if (i == 0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, i);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, i);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
if (has_tmp_block) {
|
||||
Copy(tmp_block, out_data, blen, unsigned char);
|
||||
out_data += blen;
|
||||
}
|
||||
rv = ecb_decrypt(in_data+in_data_start, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
} /* in_data_len>0 */
|
||||
else if (has_tmp_block) {
|
||||
RETVAL = newSVpvn((char*)tmp_block, blen);
|
||||
}
|
||||
else {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish_dec(Crypt::Mode::ECB self)
|
||||
CODE:
|
||||
{
|
||||
unsigned char tmp_block[MAXBLOCKSIZE];
|
||||
unsigned char i;
|
||||
int rv, rv_len, blen;
|
||||
|
||||
rv_len = 0;
|
||||
if (self->padlen > 0) {
|
||||
blen = (&self->state)->blocklen;
|
||||
if (self->padlen != blen) croak("FATAL: cipher text length has to be multiple of %d (%d)", blen, self->padlen);
|
||||
rv = ecb_decrypt(self->pad, tmp_block, blen, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecb_decrypt failed: %s", error_to_string(rv));
|
||||
if(self->padding_mode == 0) { /* no padding */
|
||||
rv_len = blen;
|
||||
}
|
||||
else if(self->padding_mode == 1) { /* pkcs5|7 padding */
|
||||
i = tmp_block[blen-1];
|
||||
rv_len = blen - (i>blen ? blen : i);
|
||||
}
|
||||
else if(self->padding_mode == 2) { /* oneandzeroes padding */
|
||||
rv_len = blen;
|
||||
while ((unsigned char)tmp_block[rv_len-1] == 0x00) rv_len--;
|
||||
if ((unsigned char)tmp_block[rv_len-1] == 0x80) rv_len--;
|
||||
if (rv_len<0) rv_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn((char*)tmp_block, rv_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
98
inc/CryptX_Mode_OFB.xs.inc
Normal file
98
inc/CryptX_Mode_OFB.xs.inc
Normal file
@ -0,0 +1,98 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Mode::OFB
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
Crypt::Mode::OFB
|
||||
_new(char * cipher_name, int rounds=0)
|
||||
CODE:
|
||||
{
|
||||
Newz(0, RETVAL, 1, struct ofb_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->direction = 0;
|
||||
RETVAL->cipher_rounds = rounds;
|
||||
RETVAL->cipher_id = find_cipher(cipher_name);
|
||||
if(RETVAL->cipher_id==-1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Mode::OFB self)
|
||||
CODE:
|
||||
Safefree(self);
|
||||
|
||||
int
|
||||
_get_dir(Crypt::Mode::OFB self)
|
||||
CODE:
|
||||
RETVAL = self->direction;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_start(Crypt::Mode::OFB self, int dir, SV * key, SV * iv)
|
||||
CODE:
|
||||
{
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
STRLEN i_len=0;
|
||||
unsigned char *i=NULL;
|
||||
int rv;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
if (!SvPOK(iv)) croak("FATAL: iv must be string/buffer scalar");
|
||||
i = (unsigned char *) SvPVbyte(iv, i_len);
|
||||
if (i_len != (STRLEN)cipher_descriptor[self->cipher_id].block_length) {
|
||||
croak ("FATAL: sizeof(iv) should be equal to blocksize (%d)", cipher_descriptor[self->cipher_id].block_length);
|
||||
}
|
||||
|
||||
rv = ofb_start(self->cipher_id, i, k, (int)k_len, self->cipher_rounds, &self->state);
|
||||
if (rv != CRYPT_OK) {
|
||||
croak("FATAL: ofb_start failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
self->direction = dir;
|
||||
}
|
||||
|
||||
SV *
|
||||
_crypt(Crypt::Mode::OFB self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
|
||||
if (self->direction == 1) {
|
||||
rv = ofb_encrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ofb_encrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if (self->direction == -1) {
|
||||
rv = ofb_decrypt(in_data, out_data, (unsigned long)in_data_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ofb_decrypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
croak("FATAL: ofb_crypt failed: call start_encrypt or start_decrypt first");
|
||||
}
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_finish(Crypt::Mode::OFB self)
|
||||
CODE:
|
||||
self->direction = 0;
|
||||
RETVAL = newSVpvn("", 0);
|
||||
OUTPUT:
|
||||
RETVAL
|
426
inc/CryptX_PK_DH.xs.inc
Normal file
426
inc/CryptX_PK_DH.xs.inc
Normal file
@ -0,0 +1,426 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::PK::DH
|
||||
|
||||
Crypt::PK::DH
|
||||
_new()
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
Newz(0, RETVAL, 1, struct dh_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->key.type = -1;
|
||||
RETVAL->pindex = find_prng("chacha20");
|
||||
if(RETVAL->pindex==-1) croak("FATAL: find_prng('chacha20') failed");
|
||||
rv = rng_make_prng(320, RETVAL->pindex, &RETVAL->pstate, NULL); /* 320bits = 40bytes */
|
||||
if (rv != CRYPT_OK) croak("FATAL: rng_make_prng failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
_generate_key(Crypt::PK::DH self, int key_size=256)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
/* gen the key */
|
||||
rv = dh_make_key(&self->pstate, self->pindex, key_size, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_make_key failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_generate_key_ex(Crypt::PK::DH self, SV * g, SV * p)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN p_len = 0;
|
||||
STRLEN g_len = 0;
|
||||
unsigned char *p_ptr=NULL;
|
||||
unsigned char *g_ptr=NULL;
|
||||
|
||||
p_ptr = (unsigned char *)SvPVbyte(p, p_len);
|
||||
g_ptr = (unsigned char *)SvPVbyte(g, g_len);
|
||||
|
||||
/* gen the key */
|
||||
rv = dh_make_key_ex(&self->pstate, self->pindex, (const char *) g_ptr, (const char *) p_ptr, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_make_key_ex failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import(Crypt::PK::DH self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
if (self->key.type != -1) { dh_free(&self->key); self->key.type = -1; }
|
||||
rv = dh_import(data, (unsigned long)data_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_import failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import_raw(Crypt::PK::DH self, SV * raw_key, int type, char * g, char * p)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(raw_key, data_len);
|
||||
if (self->key.type != -1) { dh_free(&self->key); self->key.type = -1; }
|
||||
/* public */
|
||||
if (type == 0) {
|
||||
rv = dh_import_raw(data, (unsigned long)data_len, PK_PUBLIC, g, p, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_import_raw failed: %s", error_to_string(rv));
|
||||
}
|
||||
/* private */
|
||||
else if (type == 1) {
|
||||
rv = dh_import_raw(data, (unsigned long)data_len, PK_PRIVATE, g, p, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_import_raw failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
croak("FATAL: import_raw invalid type '%d'", type);
|
||||
}
|
||||
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
int
|
||||
is_private(Crypt::PK::DH self)
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
RETVAL = (self->key.type == PK_PRIVATE) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
size(Crypt::PK::DH self)
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
RETVAL = dh_get_size(&self->key);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
key2hash(Crypt::PK::DH self)
|
||||
PREINIT:
|
||||
HV *rv_hash;
|
||||
long siz;
|
||||
char buf[20001];
|
||||
SV **not_used;
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
rv_hash = newHV();
|
||||
/* =====> x */
|
||||
siz = (self->key.x) ? mp_unsigned_bin_size(self->key.x) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'x' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.x, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "x", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "x", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> y */
|
||||
siz = (self->key.y) ? mp_unsigned_bin_size(self->key.y) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'y' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.y, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "y", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "y", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> p */
|
||||
siz = (self->key.prime) ? mp_unsigned_bin_size(self->key.prime) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'p' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.prime, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else {
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
|
||||
/* =====> g */
|
||||
siz = (self->key.base) ? mp_unsigned_bin_size(self->key.base) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'g' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.base, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else {
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> size */
|
||||
not_used = hv_store(rv_hash, "size", 4, newSViv(dh_get_size(&self->key)), 0);
|
||||
/* =====> type */
|
||||
not_used = hv_store(rv_hash, "type", 4, newSViv(self->key.type), 0);
|
||||
if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
|
||||
RETVAL = newRV_noinc((SV*)rv_hash);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
params2hash(Crypt::PK::DH self)
|
||||
PREINIT:
|
||||
HV *rv_hash;
|
||||
long siz;
|
||||
char buf[20001];
|
||||
SV **not_used;
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
rv_hash = newHV();
|
||||
/* =====> p */
|
||||
siz = (self->key.prime) ? mp_unsigned_bin_size(self->key.prime) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'p' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.prime, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else {
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
|
||||
/* =====> g */
|
||||
siz = (self->key.base) ? mp_unsigned_bin_size(self->key.base) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'g' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.base, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else {
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
|
||||
RETVAL = newRV_noinc((SV*)rv_hash);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
export_key(Crypt::PK::DH self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long int out_len = 4096;
|
||||
unsigned char out[4096];
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private", 7)) {
|
||||
rv = dh_export(out, &out_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_export(PK_PRIVATE) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
rv = dh_export(out, &out_len, PK_PUBLIC, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_export(PK_PUBLIC) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_der invalid type '%s'", type);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::PK::DH self, SV * data, char * hash_name)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned long buffer_len = 1024;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = dh_encrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_encrypt_key failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::PK::DH self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned long buffer_len = 1024;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
rv = dh_decrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_decrypt_key failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_sign(Crypt::PK::DH self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned long buffer_len = 1024;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
rv = dh_sign_hash(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
&self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_sign_hash failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_verify(Crypt::PK::DH self, SV * sig, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, stat;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char *sig_ptr=NULL;
|
||||
STRLEN sig_len=0;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
|
||||
|
||||
RETVAL = 1;
|
||||
rv = dh_verify_hash(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
|
||||
if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
shared_secret(Crypt::PK::DH self, Crypt::PK::DH pubkey)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long buffer_len = 1024;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
rv = dh_shared_secret(&self->key, &pubkey->key, buffer, &buffer_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dh_shared_secret failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
export_key_raw(Crypt::PK::DH self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned long len, buffer_len = 1024;
|
||||
unsigned char buffer[1024];
|
||||
void *key;
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private", 7)) {
|
||||
key = self->key.x;
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
key = self->key.y;
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_raw: invalid type '%s'", type);
|
||||
}
|
||||
|
||||
len = (unsigned long)mp_unsigned_bin_size(key);
|
||||
if (buffer_len < len) {
|
||||
croak("FATAL: %s", error_to_string(CRYPT_BUFFER_OVERFLOW));
|
||||
}
|
||||
rv = mp_to_unsigned_bin(key, buffer);
|
||||
if (rv != CRYPT_OK) croak("FATAL: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_is_pubkey_valid(Crypt::PK::DH self);
|
||||
CODE:
|
||||
{
|
||||
int rv, i, bits_set = 0;
|
||||
mp_int one, two, p1, *y;
|
||||
mp_digit digit;
|
||||
|
||||
if ((rv = mp_init_multi(&one, &two, &p1, NULL)) != MP_OKAY) {
|
||||
croak("FATAL: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
y = self->key.y;
|
||||
mp_set(&one, 1);
|
||||
mp_set(&two, 2);
|
||||
|
||||
/* p1 = p-1 */
|
||||
if ((rv = mp_sub(self->key.prime, &one, &p1)) != MP_OKAY) {
|
||||
croak("FATAL: %s", error_to_string(rv));
|
||||
}
|
||||
/* valid public key cannot be negative */
|
||||
if (y->sign == MP_NEG) {
|
||||
RETVAL = 0;
|
||||
}
|
||||
/* valid public key != 1 */
|
||||
else if (mp_cmp(y, &one) == MP_EQ) {
|
||||
RETVAL = 0;
|
||||
}
|
||||
/* public key cannot be > p-1 */
|
||||
else if (mp_cmp(y, &p1) == MP_GT) {
|
||||
RETVAL = 0;
|
||||
}
|
||||
/* if base == 2, public must have more than one bit set */
|
||||
else if (mp_cmp(self->key.base, &two) == MP_EQ) {
|
||||
for (i = 0; i < y->used; i++) {
|
||||
digit = y->dp[i];
|
||||
while (digit > ((mp_digit) 0)) {
|
||||
if (digit & ((mp_digit) 1))
|
||||
bits_set++;
|
||||
digit >>= ((mp_digit) 1);
|
||||
}
|
||||
}
|
||||
if (bits_set > 1)
|
||||
RETVAL = 1;
|
||||
else RETVAL = 0;
|
||||
}
|
||||
else RETVAL = 1;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::PK::DH self)
|
||||
CODE:
|
||||
if (self->key.type != -1) { dh_free(&self->key); self->key.type = -1; }
|
||||
Safefree(self);
|
||||
|
275
inc/CryptX_PK_DSA.xs.inc
Normal file
275
inc/CryptX_PK_DSA.xs.inc
Normal file
@ -0,0 +1,275 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::PK::DSA
|
||||
|
||||
Crypt::PK::DSA
|
||||
_new()
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
Newz(0, RETVAL, 1, struct dsa_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->key.type = -1;
|
||||
RETVAL->pindex = find_prng("chacha20");
|
||||
if(RETVAL->pindex==-1) croak("FATAL: find_prng('chacha20') failed");
|
||||
rv = rng_make_prng(320, RETVAL->pindex, &RETVAL->pstate, NULL); /* 320bits = 40bytes */
|
||||
if (rv != CRYPT_OK) croak("FATAL: rng_make_prng failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
generate_key(Crypt::PK::DSA self, int group_size=30, int modulus_size=256)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
/* gen the key */
|
||||
rv = dsa_make_key(&self->pstate, self->pindex, group_size, modulus_size, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_make_key failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import(Crypt::PK::DSA self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
if (self->key.type != -1) { dsa_free(&self->key); self->key.type = -1; }
|
||||
rv = dsa_import(data, (unsigned long)data_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_import failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import_hex(Crypt::PK::DSA self, char *p, char *q, char *g, char *x, char *y)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
if (self->key.type != -1) { dsa_free(&self->key); self->key.type = -1; }
|
||||
rv = dsa_import_radix(16, p, q, g, x, y, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_import_radix failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
int
|
||||
is_private(Crypt::PK::DSA self)
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.qord <= 0) XSRETURN_UNDEF;
|
||||
RETVAL = (self->key.type == PK_PRIVATE) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
size(Crypt::PK::DSA self)
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.qord <= 0) XSRETURN_UNDEF;
|
||||
RETVAL = mp_unsigned_bin_size(self->key.g);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
size_q(Crypt::PK::DSA self)
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.qord <= 0) XSRETURN_UNDEF;
|
||||
RETVAL = self->key.qord;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
key2hash(Crypt::PK::DSA self)
|
||||
PREINIT:
|
||||
HV *rv_hash;
|
||||
long siz, qsize, psize;
|
||||
char buf[20001];
|
||||
SV **not_used;
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.qord <= 0) XSRETURN_UNDEF;
|
||||
qsize = mp_unsigned_bin_size(self->key.q);
|
||||
psize = mp_unsigned_bin_size(self->key.p);
|
||||
rv_hash = newHV();
|
||||
/* =====> g */
|
||||
siz = (self->key.g) ? mp_unsigned_bin_size(self->key.g) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'g' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.g, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "g", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> q */
|
||||
siz = (self->key.q) ? mp_unsigned_bin_size(self->key.q) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'q' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.q, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "q", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "q", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> p */
|
||||
siz = (self->key.p) ? mp_unsigned_bin_size(self->key.p) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'p' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.p, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> x */
|
||||
siz = (self->key.x) ? mp_unsigned_bin_size(self->key.x) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'x' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.x, buf, 20000, qsize*2);
|
||||
not_used = hv_store(rv_hash, "x", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "x", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> y */
|
||||
siz = (self->key.y) ? mp_unsigned_bin_size(self->key.y) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'y' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.y, buf, 20000, psize*2);
|
||||
not_used = hv_store(rv_hash, "y", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "y", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> size */
|
||||
not_used = hv_store(rv_hash, "size", 4, newSViv(qsize), 0);
|
||||
/* =====> type */
|
||||
not_used = hv_store(rv_hash, "type", 4, newSViv(self->key.type), 0);
|
||||
if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
|
||||
RETVAL = newRV_noinc((SV*)rv_hash);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
export_key_der(Crypt::PK::DSA self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char out[4096];
|
||||
unsigned long int out_len = 4096;
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private", 7)) {
|
||||
rv = dsa_export(out, &out_len, PK_PRIVATE|PK_STD, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_export(PK_PRIVATE|PK_STD) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
rv = dsa_export(out, &out_len, PK_PUBLIC|PK_STD, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_export(PK_PUBLIC|PK_STD) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_der invalid type '%s'", type);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::PK::DSA self, SV * data, char * hash_name)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = dsa_encrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_encrypt_key failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::PK::DSA self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
rv = dsa_decrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_decrypt_key_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_sign(Crypt::PK::DSA self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
rv = dsa_sign_hash(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
&self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: dsa_sign_hash_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_verify(Crypt::PK::DSA self, SV * sig, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv, stat;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char *sig_ptr=NULL;
|
||||
STRLEN sig_len=0;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
|
||||
|
||||
RETVAL = 1;
|
||||
rv = dsa_verify_hash(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
|
||||
if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::PK::DSA self)
|
||||
CODE:
|
||||
if (self->key.type != -1) { dsa_free(&self->key); self->key.type = -1; }
|
||||
Safefree(self);
|
||||
|
390
inc/CryptX_PK_ECC.xs.inc
Normal file
390
inc/CryptX_PK_ECC.xs.inc
Normal file
@ -0,0 +1,390 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::PK::ECC
|
||||
|
||||
Crypt::PK::ECC
|
||||
_new()
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
Newz(0, RETVAL, 1, struct ecc_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->pindex = find_prng("chacha20");
|
||||
RETVAL->key.type = -1;
|
||||
ecc_dp_init(&RETVAL->dp);
|
||||
if(RETVAL->pindex==-1) croak("FATAL: find_prng('chacha20') failed");
|
||||
rv = rng_make_prng(320, RETVAL->pindex, &RETVAL->pstate, NULL); /* 320bits = 40bytes */
|
||||
if (rv != CRYPT_OK) croak("FATAL: rng_make_prng failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
generate_key(Crypt::PK::ECC self, SV *curve)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
/* setup dp structure */
|
||||
_ecc_set_dp_from_SV(&self->dp, curve); /* croaks on error */
|
||||
/* gen the key */
|
||||
rv = ecc_make_key_ex(&self->pstate, self->pindex, &self->key, &self->dp);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_make_key_ex failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import(Crypt::PK::ECC self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
_ecc_free_key(&self->key, &self->dp);
|
||||
rv = ecc_import_full(data, (unsigned long)data_len, &self->key, &self->dp);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_import_full failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import_pkcs8(Crypt::PK::ECC self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
_ecc_free_key(&self->key, &self->dp);
|
||||
rv = ecc_import_pkcs8(data, (unsigned long)data_len, NULL, 0, &self->key, &self->dp);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_import_pkcs8 failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
import_key_raw(Crypt::PK::ECC self, SV * key_data, SV * curve)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
_ecc_free_key(&self->key, &self->dp);
|
||||
|
||||
_ecc_set_dp_from_SV(&self->dp, curve); /* croaks on error */
|
||||
|
||||
rv = ecc_import_raw(data, (unsigned long)data_len, &self->key, &self->dp);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_import_raw failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
int
|
||||
is_private(Crypt::PK::ECC self)
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
RETVAL = (self->key.type == PK_PRIVATE) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
size(Crypt::PK::ECC self)
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
RETVAL = ecc_get_size(&self->key);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
key2hash(Crypt::PK::ECC self)
|
||||
PREINIT:
|
||||
HV *rv_hash;
|
||||
long siz, esize;
|
||||
char buf[20001];
|
||||
SV **not_used;
|
||||
CODE:
|
||||
if (self->key.type == -1) XSRETURN_UNDEF;
|
||||
esize = ecc_get_size(&self->key);
|
||||
rv_hash = newHV();
|
||||
/* =====> k */
|
||||
siz = (self->key.k) ? mp_unsigned_bin_size(self->key.k) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'k' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.k, buf, 20000, esize*2);
|
||||
not_used = hv_store(rv_hash, "k", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "k", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> pub_x */
|
||||
siz = (self->key.pubkey.x) ? mp_unsigned_bin_size(self->key.pubkey.x) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'pub_x' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.pubkey.x, buf, 20000, esize*2);
|
||||
not_used = hv_store(rv_hash, "pub_x", 5, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "pub_x", 5, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> pub_y */
|
||||
siz = (self->key.pubkey.y) ? mp_unsigned_bin_size(self->key.pubkey.y) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'pub_y' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.pubkey.y, buf, 20000, esize*2);
|
||||
not_used = hv_store(rv_hash, "pub_y", 5, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "pub_y", 5, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> curve_... */
|
||||
if (self->key.dp) {
|
||||
not_used = hv_store(rv_hash, "curve_cofactor", 14, newSViv(self->key.dp->cofactor), 0);
|
||||
/* prepend leading zero if we have odd number of hexadecimal digits */
|
||||
strncpy(buf, self->key.dp->prime, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_prime", 11, newSVpv(buf, strlen(buf)), 0);
|
||||
strncpy(buf, self->key.dp->A, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_A", 7, newSVpv(buf, strlen(buf)), 0);
|
||||
strncpy(buf, self->key.dp->B, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_B", 7, newSVpv(buf, strlen(buf)), 0);
|
||||
strncpy(buf, self->key.dp->order, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_order", 11, newSVpv(buf, strlen(buf)), 0);
|
||||
strncpy(buf, self->key.dp->Gx, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_Gx", 8, newSVpv(buf, strlen(buf)), 0);
|
||||
strncpy(buf, self->key.dp->Gy, 20000); str_add_leading_zero(buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "curve_Gy", 8, newSVpv(buf, strlen(buf)), 0);
|
||||
/* OLD approach
|
||||
not_used = hv_store(rv_hash, "curve_prime", 11, newSVpv(self->key.dp->prime, strlen(self->key.dp->prime)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_A", 7, newSVpv(self->key.dp->A, strlen(self->key.dp->A)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_B", 7, newSVpv(self->key.dp->B, strlen(self->key.dp->B)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_order", 11, newSVpv(self->key.dp->order, strlen(self->key.dp->order)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_Gx", 8, newSVpv(self->key.dp->Gx, strlen(self->key.dp->Gx)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_Gy", 8, newSVpv(self->key.dp->Gy, strlen(self->key.dp->Gy)), 0);
|
||||
*/
|
||||
{
|
||||
mp_int p_num;
|
||||
mp_init(&p_num);
|
||||
mp_read_radix(&p_num, self->key.dp->prime, 16);
|
||||
not_used = hv_store(rv_hash, "curve_bytes", 11, newSViv(mp_unsigned_bin_size(&p_num)), 0);
|
||||
not_used = hv_store(rv_hash, "curve_bits", 10, newSViv(mp_count_bits(&p_num)), 0);
|
||||
mp_clear(&p_num);
|
||||
}
|
||||
{
|
||||
unsigned long i;
|
||||
SV *name;
|
||||
char *name_ptr;
|
||||
STRLEN name_len;
|
||||
|
||||
name = newSVpv(self->key.dp->name, strlen(self->key.dp->name));
|
||||
name_ptr = SvPV(name, name_len);
|
||||
for (i=0; i<name_len && name_ptr[i]>0; i++) name_ptr[i] = toLOWER(name_ptr[i]);
|
||||
not_used = hv_store(rv_hash, "curve_name", 10, name, 0);
|
||||
}
|
||||
if (self->key.dp->oid.OIDlen > 0) {
|
||||
unsigned long i;
|
||||
SV *oid = newSVpv("", 0);
|
||||
for(i = 0; i < self->key.dp->oid.OIDlen - 1; i++) sv_catpvf(oid, "%lu.", self->key.dp->oid.OID[i]);
|
||||
sv_catpvf(oid, "%lu", self->key.dp->oid.OID[i]);
|
||||
not_used = hv_store(rv_hash, "curve_oid", 9, oid, 0);
|
||||
}
|
||||
}
|
||||
/* =====> size */
|
||||
not_used = hv_store(rv_hash, "size", 4, newSViv(esize), 0);
|
||||
/* =====> type */
|
||||
not_used = hv_store(rv_hash, "type", 4, newSViv(self->key.type), 0);
|
||||
if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
|
||||
RETVAL = newRV_noinc((SV*)rv_hash);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
export_key_der(Crypt::PK::ECC self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char out[4096];
|
||||
unsigned long int out_len = 4096;
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private_short", 16)) {
|
||||
rv = ecc_export_full(out, &out_len, PK_PRIVATE|PK_CURVEOID, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export(PK_PRIVATE|PK_CURVEOID) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "private", 7)) {
|
||||
rv = ecc_export_full(out, &out_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export(PK_PRIVATE) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public_short", 15)) {
|
||||
rv = ecc_export_full(out, &out_len, PK_PUBLIC|PK_CURVEOID, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export(PK_PUBLIC|PK_CURVEOID) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
rv = ecc_export_full(out, &out_len, PK_PUBLIC, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export(PK_PUBLIC) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_der invalid type '%s'", type);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
export_key_raw(Crypt::PK::ECC self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char out[4096];
|
||||
unsigned long int out_len = sizeof(out);
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private", 7)) {
|
||||
rv = ecc_export_raw(out, &out_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export_raw(private) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public_compressed", 17)) {
|
||||
rv = ecc_export_raw(out, &out_len, PK_PUBLIC_COMPRESSED, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export_raw(public_compressed) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
rv = ecc_export_raw(out, &out_len, PK_PUBLIC, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_export_raw(public) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_raw invalid type '%s'", type);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::PK::ECC self, SV * data, char * hash_name)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = ecc_encrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_encrypt_key failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::PK::ECC self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
rv = ecc_decrypt_key(data_ptr, (unsigned long)data_len, buffer, &buffer_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_decrypt_key_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_sign(Crypt::PK::ECC self, SV * data)
|
||||
ALIAS:
|
||||
_sign_rfc7518 = 1
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
if (ix == 1) {
|
||||
rv = ecc_sign_hash_rfc7518(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
&self->key);
|
||||
}
|
||||
else {
|
||||
rv = ecc_sign_hash(data_ptr, (unsigned long)data_len, buffer, &buffer_len,
|
||||
&self->pstate, self->pindex,
|
||||
&self->key);
|
||||
}
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_sign_hash_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_verify(Crypt::PK::ECC self, SV * sig, SV * data)
|
||||
ALIAS:
|
||||
_verify_rfc7518 = 1
|
||||
CODE:
|
||||
{
|
||||
int rv, stat;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char *sig_ptr=NULL;
|
||||
STRLEN sig_len=0;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
|
||||
|
||||
RETVAL = 1;
|
||||
if (ix == 1) {
|
||||
rv = ecc_verify_hash_rfc7518(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
|
||||
}
|
||||
else {
|
||||
rv = ecc_verify_hash(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, &stat, &self->key);
|
||||
}
|
||||
if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
shared_secret(Crypt::PK::ECC self, Crypt::PK::ECC pubkey)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
rv = ecc_shared_secret(&self->key, &pubkey->key, buffer, &buffer_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: ecc_shared_secret failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::PK::ECC self)
|
||||
CODE:
|
||||
_ecc_free_key(&self->key, &self->dp);
|
||||
Safefree(self);
|
||||
|
419
inc/CryptX_PK_RSA.xs.inc
Normal file
419
inc/CryptX_PK_RSA.xs.inc
Normal file
@ -0,0 +1,419 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::PK::RSA
|
||||
|
||||
Crypt::PK::RSA
|
||||
_new()
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
Newz(0, RETVAL, 1, struct rsa_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
RETVAL->key.type = -1;
|
||||
RETVAL->pindex = find_prng("chacha20");
|
||||
if(RETVAL->pindex==-1) croak("FATAL: find_prng('chacha20') failed");
|
||||
rv = rng_make_prng(320, RETVAL->pindex, &RETVAL->pstate, NULL); /* 320bits = 40bytes */
|
||||
if (rv != CRYPT_OK) croak("FATAL: rng_make_prng failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
generate_key(Crypt::PK::RSA self, int key_size=256, long key_e=65537)
|
||||
PPCODE:
|
||||
{
|
||||
/* key_size is in octets */
|
||||
int rv;
|
||||
/* gen the key */
|
||||
rv = rsa_make_key(&self->pstate, self->pindex, key_size, key_e, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_make_key failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import(Crypt::PK::RSA self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
|
||||
rv = rsa_import(data, (unsigned long)data_len, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_import failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import_pkcs8(Crypt::PK::RSA self, SV * key_data)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *data=NULL;
|
||||
STRLEN data_len=0;
|
||||
|
||||
data = (unsigned char *)SvPVbyte(key_data, data_len);
|
||||
if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
|
||||
rv = rsa_import_pkcs8(data, (unsigned long)data_len, NULL, 0, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_import_pkcs8 failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
void
|
||||
_import_hex(Crypt::PK::RSA self, char *N, char *e, char *d=NULL, char *p=NULL, char *q=NULL, char *dP=NULL, char *dQ=NULL, char *qP=NULL)
|
||||
PPCODE:
|
||||
{
|
||||
int rv;
|
||||
if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
|
||||
rv = rsa_import_radix(16, N, e, d, p, q, dP, dQ, qP, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_import_radix failed: %s", error_to_string(rv));
|
||||
XPUSHs(ST(0)); /* return self */
|
||||
}
|
||||
|
||||
int
|
||||
is_private(Crypt::PK::RSA self)
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.N == NULL) XSRETURN_UNDEF;
|
||||
RETVAL = (self->key.type == PK_PRIVATE) ? 1 : 0;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
size(Crypt::PK::RSA self)
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.N == NULL) XSRETURN_UNDEF;
|
||||
RETVAL = mp_unsigned_bin_size(self->key.N);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
key2hash(Crypt::PK::RSA self)
|
||||
PREINIT:
|
||||
HV *rv_hash;
|
||||
long siz, nsize;
|
||||
char buf[20001];
|
||||
SV **not_used;
|
||||
CODE:
|
||||
if (self->key.type == -1 || self->key.N == NULL) XSRETURN_UNDEF;
|
||||
nsize = mp_unsigned_bin_size(self->key.N);
|
||||
rv_hash = newHV();
|
||||
/* =====> e */
|
||||
siz = (self->key.e) ? mp_unsigned_bin_size(self->key.e) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'e' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.e, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "e", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "e", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> d */
|
||||
siz = (self->key.d) ? mp_unsigned_bin_size(self->key.d) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'd' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.d, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "d", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "d", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> N */
|
||||
siz = (self->key.N) ? nsize : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'N' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.N, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "N", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "N", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> q */
|
||||
siz = (self->key.q) ? mp_unsigned_bin_size(self->key.q) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'q' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.q, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "q", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "q", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> p */
|
||||
siz = (self->key.p) ? mp_unsigned_bin_size(self->key.p) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'p' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.p, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "p", 1, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> qP */
|
||||
siz = (self->key.qP) ? mp_unsigned_bin_size(self->key.qP) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'qP' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.qP, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "qP", 2, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "qP", 2, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> dP */
|
||||
siz = (self->key.dP) ? mp_unsigned_bin_size(self->key.dP) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'dP' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.dP, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "dP", 2, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "dP", 2, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> dQ */
|
||||
siz = (self->key.dQ) ? mp_unsigned_bin_size(self->key.dQ) : 0;
|
||||
if (siz>10000) {
|
||||
croak("FATAL: key2hash failed - 'dQ' too big number");
|
||||
}
|
||||
if (siz>0) {
|
||||
mp_tohex_with_leading_zero(self->key.dQ, buf, 20000, 0);
|
||||
not_used = hv_store(rv_hash, "dQ", 2, newSVpv(buf, strlen(buf)), 0);
|
||||
}
|
||||
else{
|
||||
not_used = hv_store(rv_hash, "dQ", 2, newSVpv("", 0), 0);
|
||||
}
|
||||
/* =====> size */
|
||||
not_used = hv_store(rv_hash, "size", 4, newSViv(nsize), 0);
|
||||
/* =====> type */
|
||||
not_used = hv_store(rv_hash, "type", 4, newSViv(self->key.type), 0);
|
||||
if (not_used) not_used = NULL; /* just silence the warning: variable 'not_used' set but not used */
|
||||
RETVAL = newRV_noinc((SV*)rv_hash);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
export_key_der(Crypt::PK::RSA self, char * type)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char out[4096];
|
||||
unsigned long int out_len = 4096;
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(type, "private", 7)) {
|
||||
rv = rsa_export(out, &out_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_export(PK_PRIVATE) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else if (strnEQ(type, "public", 6)) {
|
||||
rv = rsa_export(out, &out_len, PK_PUBLIC|PK_STD, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_export(PK_PUBLIC|PK_STD) failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)out, out_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: export_key_der invalid type '%s'", type);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_encrypt(Crypt::PK::RSA self, SV * data, char * padding, char * oaep_hash, SV * oaep_lparam)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id;
|
||||
unsigned char *lparam_ptr=NULL;
|
||||
STRLEN lparam_len=0;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(padding, "oaep", 4)) {
|
||||
hash_id = find_hash(oaep_hash);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", oaep_hash);
|
||||
lparam_ptr = (unsigned char *)SvPVbyte(oaep_lparam, lparam_len);
|
||||
rv = rsa_encrypt_key_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, lparam_ptr, (unsigned long)lparam_len,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, LTC_PKCS_1_OAEP, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_encrypt_key_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "v1.5", 4)) {
|
||||
rv = rsa_encrypt_key_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, NULL, 0,
|
||||
&self->pstate, self->pindex,
|
||||
0, LTC_PKCS_1_V1_5, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_encrypt_key_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "none", 4)) {
|
||||
/* raw RSA */
|
||||
rv = ltc_mp.rsa_me(data_ptr, (unsigned long)data_len, buffer, &buffer_len, PK_PUBLIC, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_me failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: rsa_encrypt invalid padding '%s'", padding);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_decrypt(Crypt::PK::RSA self, SV * data, char * padding, char * oaep_hash, SV * oaep_lparam)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id, stat;
|
||||
unsigned char *lparam_ptr=NULL;
|
||||
STRLEN lparam_len=0;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(padding, "oaep", 4)) {
|
||||
hash_id = find_hash(oaep_hash);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", oaep_hash);
|
||||
lparam_ptr = (unsigned char *)SvPVbyte(oaep_lparam, lparam_len);
|
||||
rv = rsa_decrypt_key_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, lparam_ptr, (unsigned long)lparam_len,
|
||||
hash_id, LTC_PKCS_1_OAEP, &stat, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_decrypt_key_ex failed: %s", error_to_string(rv));
|
||||
if (stat != 1) croak("FATAL: rsa_decrypt - not valid OAEP packet");
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "v1.5", 4)) {
|
||||
rv = rsa_decrypt_key_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, NULL, 0,
|
||||
0, LTC_PKCS_1_V1_5, &stat, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_decrypt_key_ex failed: %s", error_to_string(rv));
|
||||
if (stat != 1) croak("FATAL: rsa_decrypt - invalid");
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "none", 4)) {
|
||||
/* raw RSA */
|
||||
rv = ltc_mp.rsa_me(data_ptr, (unsigned long)data_len, buffer, &buffer_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_me failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: rsa_encrypt invalid padding '%s'", padding);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
_sign(Crypt::PK::RSA self, SV * data, char * padding, char * hash_name=NULL, unsigned long saltlen=12)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
|
||||
RETVAL = newSVpvn(NULL, 0); /* undef */
|
||||
if (strnEQ(padding, "pss", 3)) {
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = rsa_sign_hash_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, LTC_PKCS_1_PSS,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, saltlen, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_sign_hash_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "v1.5", 4)) {
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = rsa_sign_hash_ex(data_ptr, (unsigned long)data_len, buffer, &buffer_len, LTC_PKCS_1_V1_5,
|
||||
&self->pstate, self->pindex,
|
||||
hash_id, 0, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_sign_hash_ex failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else if (strnEQ(padding, "none", 4)) {
|
||||
/* raw RSA */
|
||||
rv = ltc_mp.rsa_me(data_ptr, (unsigned long)data_len, buffer, &buffer_len, PK_PRIVATE, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_me failed: %s", error_to_string(rv));
|
||||
RETVAL = newSVpvn((char*)buffer, buffer_len);
|
||||
}
|
||||
else {
|
||||
croak("FATAL: rsa_sign invalid padding '%s'", padding);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
int
|
||||
_verify(Crypt::PK::RSA self, SV * sig, SV * data, char * padding, char * hash_name=NULL, unsigned long saltlen=12)
|
||||
CODE:
|
||||
{
|
||||
int rv, hash_id, stat;
|
||||
unsigned char *data_ptr=NULL;
|
||||
STRLEN data_len=0;
|
||||
unsigned char *sig_ptr=NULL;
|
||||
STRLEN sig_len=0;
|
||||
unsigned char buffer[1024];
|
||||
unsigned long i, buffer_len = 1024;
|
||||
|
||||
data_ptr = (unsigned char *)SvPVbyte(data, data_len);
|
||||
sig_ptr = (unsigned char *)SvPVbyte(sig, sig_len);
|
||||
|
||||
RETVAL = 1;
|
||||
if (strnEQ(padding, "pss", 3)) {
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = rsa_verify_hash_ex(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, LTC_PKCS_1_PSS,
|
||||
hash_id, saltlen, &stat, &self->key);
|
||||
if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
|
||||
}
|
||||
else if (strnEQ(padding, "v1.5", 4)) {
|
||||
hash_id = find_hash(hash_name);
|
||||
if(hash_id==-1) croak("FATAL: find_hash failed for '%s'", hash_name);
|
||||
rv = rsa_verify_hash_ex(sig_ptr, (unsigned long)sig_len, data_ptr, (unsigned long)data_len, LTC_PKCS_1_V1_5,
|
||||
hash_id, 0, &stat, &self->key);
|
||||
if (rv != CRYPT_OK || stat != 1) RETVAL = 0;
|
||||
}
|
||||
else if (strnEQ(padding, "none", 4)) {
|
||||
/* raw RSA */
|
||||
Zero(buffer, buffer_len, unsigned char);
|
||||
rv = ltc_mp.rsa_me(sig_ptr, (unsigned long)sig_len, buffer, &buffer_len, PK_PUBLIC, &self->key);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rsa_me failed: %s", error_to_string(rv));
|
||||
if (data_len <= buffer_len && buffer_len > 0 && data_len > 0) {
|
||||
for (i = 0; i < buffer_len - data_len; i++) if (buffer[i] != 0) RETVAL = 0;
|
||||
if (memNE(data_ptr, buffer + buffer_len - data_len, data_len)) RETVAL = 0;
|
||||
}
|
||||
else {
|
||||
RETVAL = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
croak("FATAL: rsa_verify invalid padding '%s'", padding);
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::PK::RSA self)
|
||||
CODE:
|
||||
if (self->key.type != -1) { rsa_free(&self->key); self->key.type = -1; }
|
||||
Safefree(self);
|
||||
|
144
inc/CryptX_PRNG.xs.inc
Normal file
144
inc/CryptX_PRNG.xs.inc
Normal file
@ -0,0 +1,144 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::PRNG
|
||||
|
||||
Crypt::PRNG
|
||||
_new(IV curpid, char * prng_name, SV * entropy=&PL_sv_undef)
|
||||
CODE:
|
||||
{
|
||||
int rv, id;
|
||||
unsigned char *ent=NULL;
|
||||
STRLEN ent_len=0;
|
||||
unsigned char entropy_buf[40];
|
||||
|
||||
Newz(0, RETVAL, 1, struct prng_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
id = find_prng(prng_name);
|
||||
if(id==-1) croak("FATAL: find_prng failed for '%s'", prng_name);
|
||||
RETVAL->id = id;
|
||||
RETVAL->last_pid = curpid;
|
||||
RETVAL->desc = &prng_descriptor[id];
|
||||
|
||||
rv = RETVAL->desc->start(&RETVAL->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_start failed: %s", error_to_string(rv));
|
||||
|
||||
if(SvOK(entropy)) {
|
||||
ent = (unsigned char *) SvPVbyte(entropy, ent_len);
|
||||
rv = RETVAL->desc->add_entropy(ent, (unsigned long)ent_len, &RETVAL->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
if (rng_get_bytes(entropy_buf, 40, NULL) != 40) croak("FATAL: rng_get_bytes failed: %s", error_to_string(rv));
|
||||
rv = RETVAL->desc->add_entropy(entropy_buf, 40, &RETVAL->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv));
|
||||
}
|
||||
rv = RETVAL->desc->ready(&RETVAL->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::PRNG self)
|
||||
CODE:
|
||||
{
|
||||
Safefree(self);
|
||||
}
|
||||
|
||||
void
|
||||
add_entropy(Crypt::PRNG self, SV * entropy=&PL_sv_undef)
|
||||
CODE:
|
||||
{
|
||||
STRLEN in_len=0;
|
||||
unsigned char *in_buffer=NULL;
|
||||
unsigned char entropy_buf[32];
|
||||
int rv;
|
||||
if(SvOK(entropy)) {
|
||||
in_buffer = (unsigned char *) SvPVbyte(entropy, in_len);
|
||||
rv = self->desc->add_entropy(in_buffer, (unsigned long)in_len, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
if (rng_get_bytes(entropy_buf, 32, NULL) != 32) croak("FATAL: rng_get_bytes failed");
|
||||
rv = self->desc->add_entropy(entropy_buf, 32, &self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv));
|
||||
}
|
||||
rv = self->desc->ready(&self->state);
|
||||
if (rv != CRYPT_OK) croak("FATAL: PRNG_ready failed: %s", error_to_string(rv));
|
||||
}
|
||||
|
||||
SV *
|
||||
_bytes(Crypt::PRNG self, IV curpid, STRLEN output_len)
|
||||
CODE:
|
||||
{
|
||||
int rv_len;
|
||||
unsigned char *rdata;
|
||||
unsigned char entropy_buf[32];
|
||||
|
||||
if (self->last_pid != curpid) {
|
||||
rng_get_bytes(entropy_buf, 32, NULL);
|
||||
self->desc->add_entropy(entropy_buf, 32, &self->state);
|
||||
self->desc->ready(&self->state);
|
||||
self->last_pid = curpid;
|
||||
}
|
||||
|
||||
RETVAL = NEWSV(0, output_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, output_len);
|
||||
rdata = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv_len = (self->desc->read)(rdata, (unsigned long)output_len, &self->state);
|
||||
if ((UV)rv_len != output_len) croak("FATAL: PRNG_read failed");
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
UV
|
||||
_int32(Crypt::PRNG self, IV curpid)
|
||||
CODE:
|
||||
{
|
||||
int i;
|
||||
unsigned char rdata[4];
|
||||
unsigned char entropy_buf[32];
|
||||
|
||||
if (self->last_pid != curpid) {
|
||||
rng_get_bytes(entropy_buf, 32, NULL);
|
||||
self->desc->add_entropy(entropy_buf, 32, &self->state);
|
||||
self->desc->ready(&self->state);
|
||||
self->last_pid = curpid;
|
||||
}
|
||||
|
||||
i = (self->desc->read)(rdata, 4, &self->state);
|
||||
if (i != 4) croak("FATAL: PRNG_read failed");
|
||||
RETVAL = ((UV)(rdata[0])<<24) + ((UV)(rdata[1])<<16) + ((UV)(rdata[2])<<8) + ((UV)(rdata[3]));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
NV
|
||||
_double(Crypt::PRNG self, IV curpid, ...)
|
||||
CODE:
|
||||
{
|
||||
int i;
|
||||
unsigned long a, b; /* 32bit is enough */
|
||||
unsigned char rdata[7]; /* for double we need 53 bits */
|
||||
unsigned char entropy_buf[32];
|
||||
NV limit;
|
||||
|
||||
if (self->last_pid != curpid) {
|
||||
rng_get_bytes(entropy_buf, 32, NULL);
|
||||
self->desc->add_entropy(entropy_buf, 32, &self->state);
|
||||
self->desc->ready(&self->state);
|
||||
self->last_pid = curpid;
|
||||
}
|
||||
|
||||
i = (self->desc->read)(rdata, 7, &self->state);
|
||||
if (i != 7) croak("FATAL: PRNG_read failed");
|
||||
a = (((unsigned long)(rdata[0])<<16) + ((unsigned long)(rdata[1])<<8) + ((unsigned long)(rdata[2]))) & 0x1FFFFF; /* 21 bits */
|
||||
b = ((unsigned long)(rdata[3])<<24) + ((unsigned long)(rdata[4])<<16) + ((unsigned long)(rdata[5])<<8) + ((unsigned long)(rdata[6])); /* 32 bits */
|
||||
RETVAL = ( (NV)a * 4294967296.0 + (NV)b ) / 9007199254740992.0; /* (a * 2^32 + b) / 2^53 */
|
||||
if (items>2 && SvOK(ST(2))) {
|
||||
limit = SvNV(ST(2));
|
||||
if (limit > 0 || limit < 0) RETVAL = RETVAL * limit;
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
91
inc/CryptX_Stream_ChaCha.xs.inc
Normal file
91
inc/CryptX_Stream_ChaCha.xs.inc
Normal file
@ -0,0 +1,91 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Stream::ChaCha
|
||||
|
||||
Crypt::Stream::ChaCha
|
||||
_new(SV * key, SV * nonce, UV counter = 0, int rounds = 20)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN iv_len=0, k_len=0;
|
||||
unsigned char *iv=NULL, *k=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
iv = (unsigned char *) SvPVbyte(nonce, iv_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct chacha_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = chacha_setup(&RETVAL->state, k, (unsigned long)k_len, rounds);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha_setup failed: %s", error_to_string(rv));
|
||||
|
||||
if (iv_len == 12) {
|
||||
rv = chacha_ivctr32(&RETVAL->state, iv, (unsigned long)iv_len, (ulong32)counter);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha_ivctr32 failed: %s", error_to_string(rv));
|
||||
}
|
||||
else if (iv_len == 8) {
|
||||
rv = chacha_ivctr64(&RETVAL->state, iv, (unsigned long)iv_len, (ulong64)counter);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha_ivctr64 failed: %s", error_to_string(rv));
|
||||
}
|
||||
else {
|
||||
croak("FATAL: chacha IV length must be 8 or 12 bytes");
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Stream::ChaCha self)
|
||||
CODE:
|
||||
chacha_done(&self->state);
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Stream::ChaCha
|
||||
clone(Crypt::Stream::ChaCha self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct chacha_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct chacha_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
keystream(Crypt::Stream::ChaCha self, STRLEN out_len)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *out_data;
|
||||
|
||||
RETVAL = NEWSV(0, out_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, out_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = chacha_keystream(&self->state, out_data, out_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha_keystream failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
crypt(Crypt::Stream::ChaCha self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = chacha_crypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: chacha_crypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
77
inc/CryptX_Stream_RC4.xs.inc
Normal file
77
inc/CryptX_Stream_RC4.xs.inc
Normal file
@ -0,0 +1,77 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Stream::RC4
|
||||
|
||||
Crypt::Stream::RC4
|
||||
_new(SV * key)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN k_len=0;
|
||||
unsigned char *k=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct rc4_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = rc4_stream_setup(&RETVAL->state, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rc4_stream_setup failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Stream::RC4 self)
|
||||
CODE:
|
||||
rc4_stream_done(&self->state);
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Stream::RC4
|
||||
clone(Crypt::Stream::RC4 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct rc4_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct rc4_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
keystream(Crypt::Stream::RC4 self, STRLEN out_len)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *out_data;
|
||||
|
||||
RETVAL = NEWSV(0, out_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, out_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = rc4_stream_keystream(&self->state, out_data, out_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rc4_stream_keystream failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
crypt(Crypt::Stream::RC4 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = rc4_stream_crypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: rc4_stream_crypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
82
inc/CryptX_Stream_Sober128.xs.inc
Normal file
82
inc/CryptX_Stream_Sober128.xs.inc
Normal file
@ -0,0 +1,82 @@
|
||||
MODULE = CryptX PACKAGE = Crypt::Stream::Sober128
|
||||
|
||||
Crypt::Stream::Sober128
|
||||
_new(SV * key, SV * nonce)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN iv_len=0, k_len=0;
|
||||
unsigned char *iv=NULL, *k=NULL;
|
||||
|
||||
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
|
||||
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar");
|
||||
k = (unsigned char *) SvPVbyte(key, k_len);
|
||||
iv = (unsigned char *) SvPVbyte(nonce, iv_len);
|
||||
|
||||
Newz(0, RETVAL, 1, struct sober128_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
|
||||
rv = sober128_stream_setup(&RETVAL->state, k, (unsigned long)k_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sober128_stream_setup failed: %s", error_to_string(rv));
|
||||
|
||||
rv = sober128_stream_setiv(&RETVAL->state, iv, (unsigned long)iv_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sober128_stream_setiv failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
DESTROY(Crypt::Stream::Sober128 self)
|
||||
CODE:
|
||||
sober128_stream_done(&self->state);
|
||||
Safefree(self);
|
||||
|
||||
Crypt::Stream::Sober128
|
||||
clone(Crypt::Stream::Sober128 self)
|
||||
CODE:
|
||||
Newz(0, RETVAL, 1, struct sober128_struct);
|
||||
if (!RETVAL) croak("FATAL: Newz failed");
|
||||
Copy(&self->state, &RETVAL->state, 1, struct sober128_struct);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
keystream(Crypt::Stream::Sober128 self, STRLEN out_len)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
unsigned char *out_data;
|
||||
|
||||
RETVAL = NEWSV(0, out_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, out_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = sober128_stream_keystream(&self->state, out_data, out_len);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sober128_stream_keystream failed: %s", error_to_string(rv));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV *
|
||||
crypt(Crypt::Stream::Sober128 self, SV * data)
|
||||
CODE:
|
||||
{
|
||||
int rv;
|
||||
STRLEN in_data_len;
|
||||
unsigned char *in_data, *out_data;
|
||||
|
||||
in_data = (unsigned char *)SvPVbyte(data, in_data_len);
|
||||
if (in_data_len==0) {
|
||||
RETVAL = newSVpvn("", 0);
|
||||
}
|
||||
else {
|
||||
RETVAL = NEWSV(0, in_data_len);
|
||||
SvPOK_only(RETVAL);
|
||||
SvCUR_set(RETVAL, in_data_len);
|
||||
out_data = (unsigned char *)SvPV_nolen(RETVAL);
|
||||
rv = sober128_stream_crypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
|
||||
if (rv != CRYPT_OK) croak("FATAL: sober128_stream_crypt failed: %s", error_to_string(rv));
|
||||
}
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
17
lib/Crypt/AuthEnc.pm
Normal file
17
lib/Crypt/AuthEnc.pm
Normal file
@ -0,0 +1,17 @@
|
||||
package Crypt::AuthEnc;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc - [internal only]
|
||||
|
||||
=cut
|
100
lib/Crypt/AuthEnc/CCM.pm
Normal file
100
lib/Crypt/AuthEnc/CCM.pm
Normal file
@ -0,0 +1,100 @@
|
||||
package Crypt::AuthEnc::CCM;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::AuthEnc Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ccm_encrypt_authenticate ccm_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use CryptX;
|
||||
use Crypt::Cipher;
|
||||
|
||||
### the following functions are implemented in XS:
|
||||
# - _memory_encrypt
|
||||
# - _memory_decrypt
|
||||
|
||||
sub ccm_encrypt_authenticate {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $nonce = shift;
|
||||
my $adata = shift;
|
||||
my $tag_len = shift;
|
||||
my $plaintext = shift;
|
||||
return _memory_encrypt(Crypt::Cipher::_trans_cipher_name($cipher_name), $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
}
|
||||
|
||||
sub ccm_decrypt_verify {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $nonce = shift;
|
||||
my $adata = shift;
|
||||
my $ciphertext = shift;
|
||||
my $tag = shift;
|
||||
return _memory_decrypt(Crypt::Cipher::_trans_cipher_name($cipher_name), $key, $nonce, $adata, $ciphertext, $tag);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::CCM - Authenticated encryption in CCM mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::CCM qw(ccm_encrypt_authenticate ccm_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = ccm_encrypt_authenticate('AES', $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
my $plaintext = ccm_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
CCM is a encrypt+authenticate mode that is centered around using AES (or any 16-byte cipher) as aprimitive.
|
||||
Unlike EAX and OCB mode, it is only meant for packet mode where the length of the input is known in advance.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::CCM qw(ccm_encrypt_authenticate ccm_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ccm_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = ccm_encrypt_authenticate($cipher, $key, $nonce, $adata, $tag_len, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... key of proper length (e.g. 128/192/256bits for AES)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
# $tag_len . required length of output tag
|
||||
|
||||
CCM parameters should follow L<http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38c.pdf>
|
||||
|
||||
# tag length: 4, 6, 8, 10, 12, 14, 16 (reasonable minimum is 8)
|
||||
# nonce length: 7, 8, 9, 10, 11, 12, 13 (if you are not sure, use 11)
|
||||
# BEWARE nonce length determines max. enc/dec data size: max_data_size = 2^(8*(15-nonce_len))
|
||||
|
||||
=head2 ccm_decrypt_verify
|
||||
|
||||
my $plaintext = ccm_decrypt_verify($cipher, $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
# on error returns undef
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/CCM_mode|https://en.wikipedia.org/wiki/CCM_mode>
|
||||
|
||||
=back
|
164
lib/Crypt/AuthEnc/ChaCha20Poly1305.pm
Normal file
164
lib/Crypt/AuthEnc/ChaCha20Poly1305.pm
Normal file
@ -0,0 +1,164 @@
|
||||
package Crypt::AuthEnc::ChaCha20Poly1305;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::AuthEnc Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use CryptX;
|
||||
|
||||
sub new { my $class = shift; _new(@_) }
|
||||
|
||||
sub chacha20poly1305_encrypt_authenticate {
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $plaintext = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$m->adata_add(defined $adata ? $adata : ''); #XXX-TODO if no aad we have to pass empty string
|
||||
my $ct = $m->encrypt_add($plaintext);
|
||||
my $tag = $m->encrypt_done;
|
||||
return ($ct, $tag);
|
||||
}
|
||||
|
||||
sub chacha20poly1305_decrypt_verify {
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $ciphertext = shift;
|
||||
my $tag = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$m->adata_add(defined $adata ? $adata : ''); #XXX-TODO if no aad we have to pass empty string
|
||||
my $ct = $m->decrypt_add($ciphertext);
|
||||
return $m->decrypt_done($tag) ? $ct : undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::ChaCha20Poly1305 - Authenticated encryption in ChaCha20Poly1305 mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$ct = $ae->encrypt_add('data1');
|
||||
$ct = $ae->encrypt_add('data2');
|
||||
$ct = $ae->encrypt_add('data3');
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt = $ae->decrypt_add('ciphertext2');
|
||||
$pt = $ae->decrypt_add('ciphertext3');
|
||||
$tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag) die "decrypt failed";
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
|
||||
my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides encryption and authentication based on ChaCha20 + Poly1305 as defined in RFC 7539 - L<https://tools.ietf.org/html/rfc7539>
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 chacha20poly1305_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
|
||||
|
||||
# $key ..... key of proper length (128 or 256 bits / 16 or 32 bytes)
|
||||
# $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
|
||||
# $adata ... additional authenticated data (optional)
|
||||
|
||||
=head2 chacha20poly1305_decrypt_verify
|
||||
|
||||
my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
|
||||
|
||||
# $key ..... encryption key of proper length (128 or 256 bits / 16 or 32 bytes)
|
||||
# $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
|
||||
|
||||
=head2 aad_add
|
||||
|
||||
Can be called before the first C<encrypt_add> or C<decrypt_add>;
|
||||
|
||||
$ae->aad_add($aad_data); #can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); #can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); #can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
#or
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head2 set_iv
|
||||
|
||||
$ae->set_iv($iv);
|
||||
|
||||
=head2 set_iv_rfc7905
|
||||
|
||||
$ae->set_iv_rfc7905($iv, $seqnum);
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7539>
|
||||
|
||||
=back
|
179
lib/Crypt/AuthEnc/EAX.pm
Normal file
179
lib/Crypt/AuthEnc/EAX.pm
Normal file
@ -0,0 +1,179 @@
|
||||
package Crypt::AuthEnc::EAX;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::AuthEnc Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( eax_encrypt_authenticate eax_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use CryptX;
|
||||
use Crypt::Cipher;
|
||||
|
||||
### the following methods/functions are implemented in XS:
|
||||
# - _new
|
||||
# - DESTROY
|
||||
# - clone
|
||||
# - encrypt_add
|
||||
# - encrypt_done
|
||||
# - decrypt_add
|
||||
# - decrypt_done
|
||||
# - aad_add
|
||||
|
||||
sub new { my $class = shift; _new(Crypt::Cipher::_trans_cipher_name(shift), @_) }
|
||||
|
||||
sub eax_encrypt_authenticate {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $plaintext = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::EAX->new($cipher_name, $key, $iv);
|
||||
$m->aad_add($adata) if defined $adata;
|
||||
my $ct = $m->encrypt_add($plaintext);
|
||||
my $tag = $m->encrypt_done;
|
||||
return ($ct, $tag);
|
||||
}
|
||||
|
||||
sub eax_decrypt_verify {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $ciphertext = shift;
|
||||
my $tag = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::EAX->new($cipher_name, $key, $iv);
|
||||
$m->aad_add($adata) if defined $adata;
|
||||
my $ct = $m->decrypt_add($ciphertext);
|
||||
return $m->decrypt_done($tag) ? $ct : undef;
|
||||
}
|
||||
|
||||
sub header_add {
|
||||
# obsolete, only for backwards compatibility
|
||||
shift->aad_add(@_);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::EAX - Authenticated encryption in EAX mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::EAX;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$ct = $ae->encrypt_add('data1');
|
||||
$ct = $ae->encrypt_add('data2');
|
||||
$ct = $ae->encrypt_add('data3');
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt = $ae->decrypt_add('ciphertext2');
|
||||
$pt = $ae->decrypt_add('ciphertext3');
|
||||
$tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag) die "decrypt failed";
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = eax_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
|
||||
my $plaintext = eax_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
EAX is a mode that requires a cipher, CTR and OMAC support and provides encryption and authentication.
|
||||
It is initialized with a random IV that can be shared publicly, additional authenticated data which can
|
||||
be fixed and public, and a random secret symmetric key.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 eax_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = eax_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... unique initialization vector (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
|
||||
=head2 eax_decrypt_verify
|
||||
|
||||
my $plaintext = eax_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv);
|
||||
#or
|
||||
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv, $adata);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... unique initialization vector (no need to keep it secret)
|
||||
# $adata ... additional authenticated data (optional)
|
||||
|
||||
=head2 aad_add
|
||||
|
||||
$ae->aad_add($adata); #can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); #can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); #can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
#or
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::GCM|Crypt::AuthEnc::GCM>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/EAX_mode|https://en.wikipedia.org/wiki/EAX_mode>
|
||||
|
||||
=back
|
179
lib/Crypt/AuthEnc/GCM.pm
Normal file
179
lib/Crypt/AuthEnc/GCM.pm
Normal file
@ -0,0 +1,179 @@
|
||||
package Crypt::AuthEnc::GCM;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::AuthEnc Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( gcm_encrypt_authenticate gcm_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use CryptX;
|
||||
use Crypt::Cipher;
|
||||
|
||||
sub new {
|
||||
my ($class, $cipher, $key, $iv) = @_;
|
||||
my $self = _new(Crypt::Cipher::_trans_cipher_name($cipher), $key);
|
||||
# for backwards compatibility the $iv is optional
|
||||
$self->iv_add($iv) if defined $iv;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub gcm_encrypt_authenticate {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $plaintext = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::GCM->new($cipher_name, $key);
|
||||
$m->iv_add($iv);
|
||||
$m->adata_add(defined $adata ? $adata : ''); #XXX-TODO if no aad we have to pass empty string
|
||||
my $ct = $m->encrypt_add($plaintext);
|
||||
my $tag = $m->encrypt_done;
|
||||
return ($ct, $tag);
|
||||
}
|
||||
|
||||
sub gcm_decrypt_verify {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $iv = shift;
|
||||
my $adata = shift;
|
||||
my $ciphertext = shift;
|
||||
my $tag = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::GCM->new($cipher_name, $key);
|
||||
$m->iv_add($iv);
|
||||
$m->adata_add(defined $adata ? $adata : ''); #XXX-TODO if no aad we have to pass empty string
|
||||
my $ct = $m->decrypt_add($ciphertext);
|
||||
return $m->decrypt_done($tag) ? $ct : undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::GCM;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$ct = $ae->encrypt_add('data1');
|
||||
$ct = $ae->encrypt_add('data2');
|
||||
$ct = $ae->encrypt_add('data3');
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::GCM->new("AES", $key, $iv);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt = $ae->decrypt_add('ciphertext2');
|
||||
$pt = $ae->decrypt_add('ciphertext3');
|
||||
$tag = $ae->decrypt_done();
|
||||
die "decrypt failed" unless $tag eq $expected_tag;
|
||||
|
||||
#or
|
||||
my $result = $ae->decrypt_done($expected_tag) die "decrypt failed";
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = gcm_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
|
||||
my $plaintext = gcm_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Galois/Counter Mode (GCM) - provides encryption and authentication.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 gcm_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = gcm_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $iv ...... initialization vector
|
||||
# $adata ... additional authenticated data
|
||||
|
||||
=head2 gcm_decrypt_verify
|
||||
|
||||
my $plaintext = gcm_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
|
||||
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::GCM->new($cipher, $key);
|
||||
#or
|
||||
my $ae = Crypt::AuthEnc::GCM->new($cipher, $key, $iv);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher
|
||||
# $key ..... encryption key of proper length
|
||||
# $iv ...... initialization vector (optional, you can set it later via iv_add method)
|
||||
|
||||
=head2 iv_add
|
||||
|
||||
$ae->iv_add($iv_data); #can be called multiple times
|
||||
|
||||
=head2 aad_add
|
||||
|
||||
Can be called B<after> all C<iv_add> calls but before the first C<encrypt_add> or C<decrypt_add>;
|
||||
|
||||
$ae->aad_add($aad_data); #can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); #can be called multiple times
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); #can be called multiple times
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
#or
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
|
||||
=head2 reset
|
||||
|
||||
$ae->reset;
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::AuthEnc::CCM|Crypt::AuthEnc::CCM>, L<Crypt::AuthEnc::EAX|Crypt::AuthEnc::EAX>, L<Crypt::AuthEnc::OCB|Crypt::AuthEnc::OCB>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Galois/Counter_Mode>
|
||||
|
||||
=back
|
174
lib/Crypt/AuthEnc/OCB.pm
Normal file
174
lib/Crypt/AuthEnc/OCB.pm
Normal file
@ -0,0 +1,174 @@
|
||||
package Crypt::AuthEnc::OCB;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::AuthEnc Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ocb_encrypt_authenticate ocb_decrypt_verify )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use CryptX;
|
||||
use Crypt::Cipher;
|
||||
|
||||
sub new { my $class = shift; _new(Crypt::Cipher::_trans_cipher_name(shift), @_) }
|
||||
|
||||
sub ocb_encrypt_authenticate {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $nonce = shift;
|
||||
my $adata = shift;
|
||||
my $plaintext = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce);
|
||||
$m->aad_add($adata) if defined $adata;
|
||||
my $ct = $m->encrypt_last($plaintext);
|
||||
my $tag = $m->encrypt_done;
|
||||
return ($ct, $tag);
|
||||
}
|
||||
|
||||
sub ocb_decrypt_verify {
|
||||
my $cipher_name = shift;
|
||||
my $key = shift;
|
||||
my $nonce = shift;
|
||||
my $adata = shift;
|
||||
my $ciphertext = shift;
|
||||
my $tag = shift;
|
||||
|
||||
my $m = Crypt::AuthEnc::OCB->new($cipher_name, $key, $nonce);
|
||||
$m->aad_add($adata) if defined $adata;
|
||||
my $ct = $m->decrypt_last($ciphertext);
|
||||
return $m->decrypt_done($tag) ? $ct : undef;
|
||||
}
|
||||
|
||||
sub adata_add {
|
||||
# obsolete, only for backwards compatibility
|
||||
shift->aad_add(@_);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::AuthEnc::OCB - Authenticated encryption in OCBv3 mode
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### OO interface
|
||||
use Crypt::AuthEnc::OCB;
|
||||
|
||||
# encrypt and authenticate
|
||||
my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$ct = $ae->encrypt_add('data1');
|
||||
$ct = $ae->encrypt_add('data2');
|
||||
$ct = $ae->encrypt_add('data3');
|
||||
$ct = $ae->encrypt_last('rest of data');
|
||||
($ct,$tag) = $ae->encrypt_done();
|
||||
|
||||
# decrypt and verify
|
||||
my $ae = Crypt::AuthEnc::OCB->new("AES", $key, $nonce);
|
||||
$ae->aad_add('additional_authenticated_data1');
|
||||
$ae->aad_add('additional_authenticated_data2');
|
||||
$pt = $ae->decrypt_add('ciphertext1');
|
||||
$pt = $ae->decrypt_add('ciphertext2');
|
||||
$pt = $ae->decrypt_add('ciphertext3');
|
||||
$pt = $ae->decrypt_last('rest of data');
|
||||
($pt,$tag) = $ae->decrypt_done();
|
||||
|
||||
### functional interface
|
||||
use Crypt::AuthEnc::OCB qw(ocb_encrypt_authenticate ocb_decrypt_verify);
|
||||
|
||||
my ($ciphertext, $tag) = ocb_encrypt_authenticate('AES', $key, $nonce, $adata, $plaintext);
|
||||
my $plaintext = ocb_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements OCB version 3 according http://datatracker.ietf.org/doc/draft-irtf-cfrg-ocb/
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::AuthEnc::OCB qw(ocb_encrypt_authenticate ocb_decrypt_verify);
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ocb_encrypt_authenticate
|
||||
|
||||
my ($ciphertext, $tag) = ocb_encrypt_authenticate($cipher, $key, $nonce, $adata, $plaintext);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
# $adata ... additional authenticated data
|
||||
|
||||
=head2 ocb_decrypt_verify
|
||||
|
||||
my $plaintext = ocb_decrypt_verify($cipher, $key, $nonce, $adata, $ciphertext, $tag);
|
||||
|
||||
# on error returns undef
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
my $ae = Crypt::AuthEnc::OCB->new($cipher, $key, $nonce);
|
||||
|
||||
# $cipher .. 'AES' or name of any other cipher with 16-byte block len
|
||||
# $key ..... AES key of proper length (128/192/256bits)
|
||||
# $nonce ... unique nonce/salt (no need to keep it secret)
|
||||
|
||||
=head2 aad_add
|
||||
|
||||
$ae->aad_add($adata); #can be called multiple times
|
||||
|
||||
=head2 encrypt_add
|
||||
|
||||
$ciphertext = $ae->encrypt_add($data); #can be called multiple times
|
||||
|
||||
#BEWARE: size of $data has to be multiple of blocklen (16 for AES)
|
||||
|
||||
=head2 encrypt_last
|
||||
|
||||
$ciphertext = $ae->encrypt_last($data);
|
||||
|
||||
=head2 encrypt_done
|
||||
|
||||
$tag = $ae->encrypt_done();
|
||||
|
||||
=head2 decrypt_add
|
||||
|
||||
$plaintext = $ae->decrypt_add($ciphertext); #can be called multiple times
|
||||
|
||||
#BEWARE: size of $ciphertext has to be multiple of blocklen (16 for AES)
|
||||
|
||||
=head2 encrypt_last
|
||||
|
||||
$plaintext = $ae->decrypt_last($data);
|
||||
|
||||
=head2 decrypt_done
|
||||
|
||||
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
|
||||
#or
|
||||
my $tag = $ae->decrypt_done; # returns $tag value
|
||||
|
||||
=head2 clone
|
||||
|
||||
my $ae_new = $ae->clone;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=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>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/OCB_mode|https://en.wikipedia.org/wiki/OCB_mode>
|
||||
|
||||
=back
|
197
lib/Crypt/Checksum.pm
Normal file
197
lib/Crypt/Checksum.pm
Normal file
@ -0,0 +1,197 @@
|
||||
package Crypt::Checksum;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
|
||||
our %EXPORT_TAGS = ( all => [qw/
|
||||
adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int
|
||||
crc32_data crc32_data_hex crc32_data_int crc32_file crc32_file_hex crc32_file_int
|
||||
/] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
use Crypt::Checksum::Adler32;
|
||||
use Crypt::Checksum::CRC32;
|
||||
|
||||
sub adler32_data { Crypt::Checksum::Adler32->new->add(@_)->digest }
|
||||
sub adler32_data_hex { Crypt::Checksum::Adler32->new->add(@_)->hexdigest }
|
||||
sub adler32_data_int { unpack("N", Crypt::Checksum::Adler32->new->add(@_)->digest) }
|
||||
sub adler32_file { Crypt::Checksum::Adler32->new->addfile(@_)->digest }
|
||||
sub adler32_file_hex { Crypt::Checksum::Adler32->new->addfile(@_)->hexdigest }
|
||||
sub adler32_file_int { unpack("N", Crypt::Checksum::Adler32->new->addfile(@_)->digest) }
|
||||
sub crc32_data { Crypt::Checksum::CRC32->new->add(@_)->digest }
|
||||
sub crc32_data_hex { Crypt::Checksum::CRC32->new->add(@_)->hexdigest }
|
||||
sub crc32_data_int { unpack("N", Crypt::Checksum::CRC32->new->add(@_)->digest) }
|
||||
sub crc32_file { Crypt::Checksum::CRC32->new->addfile(@_)->digest }
|
||||
sub crc32_file_hex { Crypt::Checksum::CRC32->new->addfile(@_)->hexdigest }
|
||||
sub crc32_file_int { unpack("N", Crypt::Checksum::CRC32->new->addfile(@_)->digest) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Checksum - functional interface to CRC32 and Adler32 checksums
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Crypt::Checksum ':all';
|
||||
|
||||
# calculate Adler32 checksum from string/buffer
|
||||
$checksum_raw = adler32_data($data);
|
||||
$checksum_hex = adler32_data_hex($data);
|
||||
|
||||
# calculate Adler32 checksum from file
|
||||
$checksum_raw = adler32_file('filename.dat');
|
||||
$checksum_hex = adler32_file_hex('filename.dat');
|
||||
|
||||
# calculate Adler32 checksum from filehandle
|
||||
$checksum_raw = adler32_file(*FILEHANDLE);
|
||||
$checksum_hex = adler32_file_hex(*FILEHANDLE);
|
||||
|
||||
# calculate CRC32 checksum from string/buffer
|
||||
$checksum_raw = crc32_data($data);
|
||||
$checksum_hex = crc32_data_hex($data);
|
||||
|
||||
# calculate CRC32 checksum from file
|
||||
$checksum_raw = crc32_file('filename.dat');
|
||||
$checksum_hex = crc32_file_hex('filename.dat');
|
||||
|
||||
# calculate CRC32 checksum from filehandle
|
||||
$checksum_raw = crc32_file(*FILEHANDLE);
|
||||
$checksum_hex = crc32_file_hex(*FILEHANDLE);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Calculating CRC32 and Adler32 checksums (functional interface);
|
||||
|
||||
I<Since: CryptX-0.032>
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Checksum qw( adler32_data adler32_data_hex adler32_file adler32_file_hex
|
||||
crc32_data crc32_data_hex crc32_file crc32_file_hex );
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Checksum ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 adler32_data
|
||||
|
||||
Returns checksum as raw octects.
|
||||
|
||||
$checksum_raw = adler32_data('data string');
|
||||
#or
|
||||
$checksum_raw = adler32_data('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 adler32_data_hex
|
||||
|
||||
Returns checksum as a hexadecimal string.
|
||||
|
||||
$checksum_hex = adler32_data_hex('data string');
|
||||
#or
|
||||
$checksum_hex = adler32_data_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 adler32_data_int
|
||||
|
||||
Returns checksum as unsingned 32bit integer.
|
||||
|
||||
$checksum_hex = adler32_data_int('data string');
|
||||
#or
|
||||
$checksum_hex = adler32_data_int('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 adler32_file
|
||||
|
||||
Returns checksum as raw octects.
|
||||
|
||||
$checksum_raw = adler32_file('filename.dat');
|
||||
#or
|
||||
$checksum_raw = adler32_file(*FILEHANDLE);
|
||||
|
||||
=head2 adler32_file_hex
|
||||
|
||||
Returns checksum as a hexadecimal string.
|
||||
|
||||
$checksum_hex = adler32_file_hex('filename.dat');
|
||||
#or
|
||||
$checksum_hex = adler32_file_hex(*FILEHANDLE);
|
||||
|
||||
=head2 adler32_file_int
|
||||
|
||||
Returns checksum as unsingned 32bit integer.
|
||||
|
||||
$checksum_hex = adler32_file_int('data string');
|
||||
#or
|
||||
$checksum_hex = adler32_file_int('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 crc32_data
|
||||
|
||||
Returns checksum as raw octects.
|
||||
|
||||
$checksum_raw = crc32_data('data string');
|
||||
#or
|
||||
$checksum_raw = crc32_data('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 crc32_data_hex
|
||||
|
||||
Returns checksum as a hexadecimal string.
|
||||
|
||||
$checksum_hex = crc32_data_hex('data string');
|
||||
#or
|
||||
$checksum_hex = crc32_data_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 crc32_data_int
|
||||
|
||||
Returns checksum as unsingned 32bit integer.
|
||||
|
||||
$checksum_hex = crc32_data_int('data string');
|
||||
#or
|
||||
$checksum_hex = crc32_data_int('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 crc32_file
|
||||
|
||||
Returns checksum as raw octects.
|
||||
|
||||
$checksum_raw = crc32_file('filename.dat');
|
||||
#or
|
||||
$checksum_raw = crc32_file(*FILEHANDLE);
|
||||
|
||||
=head2 crc32_file_hex
|
||||
|
||||
Returns checksum as a hexadecimal string.
|
||||
|
||||
$checksum_hex = crc32_file_hex('filename.dat');
|
||||
#or
|
||||
$checksum_hex = crc32_file_hex(*FILEHANDLE);
|
||||
|
||||
=head2 crc32_file_int
|
||||
|
||||
Returns checksum as unsingned 32bit integer.
|
||||
|
||||
$checksum_hex = crc32_file_int('data string');
|
||||
#or
|
||||
$checksum_hex = crc32_file_int('any data', 'more data', 'even more data');
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Checksum::Adler32>, L<Crypt::Checksum::CRC32>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Adler-32>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Cyclic_redundancy_check>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
121
lib/Crypt/Checksum/Adler32.pm
Normal file
121
lib/Crypt/Checksum/Adler32.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Checksum::Adler32;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
use Carp;
|
||||
use CryptX;
|
||||
|
||||
sub addfile {
|
||||
my ($self, $file) = @_;
|
||||
|
||||
my $handle;
|
||||
if (ref(\$file) eq 'SCALAR') { #filename
|
||||
open($handle, "<", $file) || croak "FATAL: cannot open '$file': $!";
|
||||
binmode($handle);
|
||||
}
|
||||
else { #handle
|
||||
$handle = $file
|
||||
}
|
||||
croak "FATAL: invalid handle" unless defined $handle;
|
||||
|
||||
my $n;
|
||||
my $buf = "";
|
||||
while (($n = read($handle, $buf, 32*1024))) {
|
||||
$self->add($buf)
|
||||
}
|
||||
croak "FATAL: read failed: $!" unless defined $n;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Checksum::Adler32 - Compute Adler32 checksum
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Crypt::Checksum::Adler32;
|
||||
|
||||
$d = Crypt::Checksum::Adler32->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$checksum_raw = $d->digest; # raw bytes
|
||||
$checksum_hex = $d->hexdigest; # hexadecimal form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Calculating Adler32 checksums (OO interface);
|
||||
|
||||
I<Since: CryptX-0.032>
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Constructor, returns a reference to the checksum object.
|
||||
|
||||
$d = Crypt::Checksum::Adler32->new;
|
||||
|
||||
=head2 clone
|
||||
|
||||
Creates a copy of the checksum object state and returns a reference to the copy.
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
Reinitialize the checksum object state and returns a reference to the checksum object.
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
All arguments are appended to the message we calculate checksum for.
|
||||
The return value is the checksum object itself.
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
The content of the file (or filehandle) is appended to the message we calculate checksum for.
|
||||
The return value is the checksum object itself.
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 digest
|
||||
|
||||
Returns the binary checksum (raw bytes).
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
Returns the checksum encoded as a hexadecimal string.
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Checksum>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Adler-32>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
121
lib/Crypt/Checksum/CRC32.pm
Normal file
121
lib/Crypt/Checksum/CRC32.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Checksum::CRC32;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
use Carp;
|
||||
use CryptX;
|
||||
|
||||
sub addfile {
|
||||
my ($self, $file) = @_;
|
||||
|
||||
my $handle;
|
||||
if (ref(\$file) eq 'SCALAR') { #filename
|
||||
open($handle, "<", $file) || croak "FATAL: cannot open '$file': $!";
|
||||
binmode($handle);
|
||||
}
|
||||
else { #handle
|
||||
$handle = $file
|
||||
}
|
||||
croak "FATAL: invalid handle" unless defined $handle;
|
||||
|
||||
my $n;
|
||||
my $buf = "";
|
||||
while (($n = read($handle, $buf, 32*1024))) {
|
||||
$self->add($buf)
|
||||
}
|
||||
croak "FATAL: read failed: $!" unless defined $n;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Checksum::CRC32 - Compute CRC32 checksum
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Crypt::Checksum::CRC32;
|
||||
|
||||
$d = Crypt::Checksum::CRC32->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$checksum_raw = $d->digest; # raw bytes
|
||||
$checksum_hex = $d->hexdigest; # hexadecimal form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Calculating CRC32 checksums (OO interface);
|
||||
|
||||
I<Since: CryptX-0.032>
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Constructor, returns a reference to the checksum object.
|
||||
|
||||
$d = Crypt::Checksum::CRC32->new;
|
||||
|
||||
=head2 clone
|
||||
|
||||
Creates a copy of the checksum object state and returns a reference to the copy.
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
Reinitialize the checksum object state and returns a reference to the checksum object.
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
All arguments are appended to the message we calculate checksum for.
|
||||
The return value is the checksum object itself.
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
The content of the file (or filehandle) is appended to the message we calculate checksum for.
|
||||
The return value is the checksum object itself.
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 digest
|
||||
|
||||
Returns the binary checksum (raw bytes).
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
Returns the checksum encoded as a hexadecimal string.
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Checksum>
|
||||
|
||||
=item * L<https://en.wikipedia.org/wiki/Cyclic_redundancy_check>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
217
lib/Crypt/Cipher.pm
Normal file
217
lib/Crypt/Cipher.pm
Normal file
@ -0,0 +1,217 @@
|
||||
package Crypt::Cipher;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
use CryptX;
|
||||
|
||||
### the following methods/functions are implemented in XS:
|
||||
# - _new
|
||||
# - DESTROY
|
||||
# - _keysize
|
||||
# - _max_keysize
|
||||
# - _min_keysize
|
||||
# - _blocksize
|
||||
# - _default_rounds
|
||||
# - encrypt
|
||||
# - decrypt
|
||||
#functions, not methods:
|
||||
# - _block_length_by_name
|
||||
# - _min_key_length_by_name
|
||||
# - _max_key_length_by_name
|
||||
# - _default_rounds_by_name
|
||||
|
||||
sub _trans_cipher_name {
|
||||
my $name = shift;
|
||||
my %trans = (
|
||||
DES_EDE => '3des',
|
||||
SAFERP => 'safer+',
|
||||
SAFER_K128 => 'safer-k128',
|
||||
SAFER_K64 => 'safer-k64',
|
||||
SAFER_SK128 => 'safer-sk128',
|
||||
SAFER_SK64 => 'safer-sk64',
|
||||
);
|
||||
$name =~ s/^Crypt::Cipher:://;
|
||||
return $trans{uc($name)} if defined $trans{uc($name)};
|
||||
return lc($name);
|
||||
}
|
||||
|
||||
### METHODS
|
||||
|
||||
sub new {
|
||||
my $pkg = shift;
|
||||
my $cipher_name = $pkg eq __PACKAGE__ ? _trans_cipher_name(shift) : _trans_cipher_name($pkg);
|
||||
return _new($cipher_name, @_);
|
||||
}
|
||||
|
||||
sub blocksize {
|
||||
my $self = shift;
|
||||
return $self->_blocksize if ref($self);
|
||||
$self = _trans_cipher_name(shift) if $self eq __PACKAGE__;
|
||||
return _block_length_by_name(_trans_cipher_name($self));
|
||||
}
|
||||
|
||||
sub keysize {
|
||||
max_keysize(@_);
|
||||
}
|
||||
|
||||
sub max_keysize
|
||||
{
|
||||
my $self = shift;
|
||||
return unless defined $self;
|
||||
return $self->_max_keysize if ref($self);
|
||||
$self = _trans_cipher_name(shift) if $self eq __PACKAGE__;
|
||||
return _max_key_length_by_name(_trans_cipher_name($self));
|
||||
}
|
||||
|
||||
sub min_keysize {
|
||||
my $self = shift;
|
||||
return unless defined $self;
|
||||
return $self->_min_keysize if ref($self);
|
||||
$self = _trans_cipher_name(shift) if $self eq __PACKAGE__;
|
||||
return _min_key_length_by_name(_trans_cipher_name($self));
|
||||
}
|
||||
|
||||
sub default_rounds {
|
||||
my $self = shift;
|
||||
return unless defined $self;
|
||||
return $self->_default_rounds if ref($self);
|
||||
$self = _trans_cipher_name(shift) if $self eq __PACKAGE__;
|
||||
return _default_rounds_by_name(_trans_cipher_name($self));
|
||||
}
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher - Generic interface to cipher functions
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#### example 1 (encrypting single block)
|
||||
use Crypt::Cipher;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $c = Crypt::Cipher->new('AES', $key);
|
||||
my $blocksize = $c->blocksize;
|
||||
my $ciphertext = $c->encrypt('plain text block'); #encrypt 1 block
|
||||
my $plaintext = $c->decrypt($ciphertext); #decrypt 1 block
|
||||
|
||||
### example 2 (using CBC mode)
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('AES');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
#### example 3 (compatibility with Crypt::CBC)
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cipher = Crypt::Cipher('AES', $key);
|
||||
my $cbc = Crypt::CBC->new( -cipher=>$cipher, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to various symetric cipher algorithms.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Constructor, returns a reference to the cipher object.
|
||||
|
||||
## basic scenario
|
||||
$d = Crypt::Cipher->new($name, $key);
|
||||
# $name = one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
|
||||
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
|
||||
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
|
||||
# 'SEED', 'Skipjack', 'Twofish', 'XTEA'
|
||||
# simply any <CNAME> for which there exists Crypt::Cipher::<NAME>
|
||||
# $key = binary key (keysize should comply with selected cipher requirements)
|
||||
|
||||
## some of the ciphers (e.g. MULTI2, RC5, SAFER) allows to set number of rounds
|
||||
$d = Crypt::Cipher->new('MULTI2', $key, $rounds);
|
||||
# $rounds = positive integer (should comply with selected cipher requirements)
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
Encrypts $plaintext and returns the $ciphertext where $plaintext and $ciphertext should be of B<blocksize> bytes.
|
||||
|
||||
$ciphertext = $d->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
Decrypts $ciphertext and returns the $plaintext where $plaintext and $ciphertext should be of B<blocksize> bytes.
|
||||
|
||||
$plaintext = $d->encrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
Just an alias for B<max_keysize> (needed for L<Crypt::CBC|Crypt::CBC> compatibility).
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
Returns the maximal allowed key size (in bytes) for given cipher.
|
||||
|
||||
$d->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher->max_keysize('AES');
|
||||
#or
|
||||
Crypt::Cipher::max_keysize('AES');
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
Returns the minimal allowed key size (in bytes) for given cipher.
|
||||
|
||||
$d->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher->min_keysize('AES');
|
||||
#or
|
||||
Crypt::Cipher::min_keysize('AES');
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
Returns block size (in bytes) for given cipher.
|
||||
|
||||
$d->blocksize;
|
||||
#or
|
||||
Crypt::Cipher->blocksize('AES');
|
||||
#or
|
||||
Crypt::Cipher::blocksize('AES');
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
Returns default number of rounds for given cipher. NOTE: only some cipher (e.g. MULTI2, RC5, SAFER) allows to set number of rounds via new().
|
||||
|
||||
$d->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher->default_rounds('AES');
|
||||
#or
|
||||
Crypt::Cipher::default_rounds('AES');
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>
|
||||
|
||||
=item * Check subclasses like L<Crypt::Cipher::AES|Crypt::Cipher::AES>, L<Crypt::Cipher::Blowfish|Crypt::Cipher::Blowfish>, ...
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/AES.pm
Normal file
121
lib/Crypt/Cipher/AES.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::AES;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::AES - Symetric cipher AES (aka Rijndael), key size: 128/192/256 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('AES');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::AES;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::AES', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the AES cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::AES->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::AES->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES->keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::AES->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::AES::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::AES::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::AES->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::AES::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Advanced_Encryption_Standard|http://en.wikipedia.org/wiki/Advanced_Encryption_Standard>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Anubis.pm
Normal file
121
lib/Crypt/Cipher/Anubis.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Anubis;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Anubis - Symetric cipher Anubis, key size: 128-320 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Anubis');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Anubis;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Anubis', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Anubis cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Anubis->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Anubis->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Anubis::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Anubis->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Anubis::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Anubis_(cipher)|http://en.wikipedia.org/wiki/Anubis_(cipher)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Blowfish.pm
Normal file
121
lib/Crypt/Cipher/Blowfish.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Blowfish;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Blowfish - Symetric cipher Blowfish, key size: 64-448 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Blowfish');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Blowfish;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Blowfish', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Blowfish cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Blowfish->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Blowfish->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Blowfish::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Blowfish_(cipher)|http://en.wikipedia.org/wiki/Blowfish_(cipher)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/CAST5.pm
Normal file
121
lib/Crypt/Cipher/CAST5.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::CAST5;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::CAST5 - Symetric cipher CAST5 (aka CAST-128), key size: 40-128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('CAST5');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::CAST5;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::CAST5', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the CAST5 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::CAST5->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::CAST5->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5->keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::CAST5::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::CAST5->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::CAST5::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/CAST-128|http://en.wikipedia.org/wiki/CAST-128>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Camellia.pm
Normal file
121
lib/Crypt/Cipher/Camellia.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Camellia;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Camellia - Symetric cipher Camellia, key size: 128/192/256 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Camellia');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Camellia;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Camellia', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Camellia cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Camellia->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Camellia->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Camellia::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Camellia->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Camellia::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Camellia_(cipher)|http://en.wikipedia.org/wiki/Camellia_(cipher)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/DES.pm
Normal file
121
lib/Crypt/Cipher/DES.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::DES;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::DES - Symetric cipher DES, key size: 64[56] bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('DES');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::DES;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::DES', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the DES cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::DES->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::DES->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES->keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::DES->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::DES::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::DES->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::DES::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Data_Encryption_Standard|http://en.wikipedia.org/wiki/Data_Encryption_Standard>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/DES_EDE.pm
Normal file
121
lib/Crypt/Cipher/DES_EDE.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::DES_EDE;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::DES_EDE - Symetric cipher DES_EDE (aka Tripple-DES, 3DES), key size: 192[168] bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('DES_EDE');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::DES_EDE;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::DES_EDE', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the DES_EDE cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::DES_EDE->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::DES_EDE->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE->keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::DES_EDE::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Triple_DES|http://en.wikipedia.org/wiki/Triple_DES>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/KASUMI.pm
Normal file
121
lib/Crypt/Cipher/KASUMI.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::KASUMI;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::KASUMI - Symetric cipher KASUMI, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('KASUMI');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::KASUMI;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::KASUMI', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the KASUMI cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::KASUMI->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::KASUMI->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI->keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::KASUMI::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/KASUMI_(block_cipher)|http://en.wikipedia.org/wiki/KASUMI_(block_cipher)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Khazad.pm
Normal file
121
lib/Crypt/Cipher/Khazad.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Khazad;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Khazad - Symetric cipher Khazad, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Khazad');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Khazad;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Khazad', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Khazad cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Khazad->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Khazad->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Khazad::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Khazad->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Khazad::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/KHAZAD|http://en.wikipedia.org/wiki/KHAZAD>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/MULTI2.pm
Normal file
121
lib/Crypt/Cipher/MULTI2.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::MULTI2;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::MULTI2 - Symetric cipher MULTI2, key size: 320 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('MULTI2');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::MULTI2;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::MULTI2', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the MULTI2 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::MULTI2->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::MULTI2->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2->keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::MULTI2::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/MULTI2|http://en.wikipedia.org/wiki/MULTI2>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Noekeon.pm
Normal file
121
lib/Crypt/Cipher/Noekeon.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Noekeon;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Noekeon - Symetric cipher Noekeon, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Noekeon');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Noekeon;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Noekeon', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Noekeon cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Noekeon->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Noekeon->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Noekeon::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/NOEKEON|http://en.wikipedia.org/wiki/NOEKEON>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/RC2.pm
Normal file
121
lib/Crypt/Cipher/RC2.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::RC2;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::RC2 - Symetric cipher RC2, key size: 64-1024 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('RC2');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::RC2;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::RC2', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the RC2 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::RC2->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::RC2->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC2->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC2::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC2::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC2->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC2::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RC2|http://en.wikipedia.org/wiki/RC2>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/RC5.pm
Normal file
121
lib/Crypt/Cipher/RC5.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::RC5;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::RC5 - Symetric cipher RC5, key size: 64-1024 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('RC5');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::RC5;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::RC5', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the RC5 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::RC5->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::RC5->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC5->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC5::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC5::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC5->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC5::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RC5|http://en.wikipedia.org/wiki/RC5>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/RC6.pm
Normal file
121
lib/Crypt/Cipher/RC6.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::RC6;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::RC6 - Symetric cipher RC6, key size: 64-1024 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('RC6');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::RC6;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::RC6', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the RC6 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::RC6->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::RC6->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6->keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC6->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::RC6::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::RC6::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC6->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::RC6::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RC6|http://en.wikipedia.org/wiki/RC6>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SAFERP.pm
Normal file
121
lib/Crypt/Cipher/SAFERP.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SAFERP;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SAFERP - Symetric cipher SAFER+, key size: 128/192/256 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SAFERP');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SAFERP;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SAFERP', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SAFERP cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SAFERP->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SAFERP->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFERP::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SAFER|http://en.wikipedia.org/wiki/SAFER>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SAFER_K128.pm
Normal file
121
lib/Crypt/Cipher/SAFER_K128.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SAFER_K128;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SAFER_K128 - Symetric cipher SAFER_K128, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SAFER_K128');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SAFER_K128;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SAFER_K128', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SAFER_K128 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SAFER_K128->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SAFER_K128->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K128::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SAFER|http://en.wikipedia.org/wiki/SAFER>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SAFER_K64.pm
Normal file
121
lib/Crypt/Cipher/SAFER_K64.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SAFER_K64;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SAFER_K64 - Symetric cipher SAFER_K64, key size: 64 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SAFER_K64');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SAFER_K64;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SAFER_K64', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SAFER_K64 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SAFER_K64->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SAFER_K64->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_K64::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SAFER|http://en.wikipedia.org/wiki/SAFER>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SAFER_SK128.pm
Normal file
121
lib/Crypt/Cipher/SAFER_SK128.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SAFER_SK128;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SAFER_SK128 - Symetric cipher SAFER_SK128, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SAFER_SK128');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SAFER_SK128;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SAFER_SK128', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SAFER_SK128 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SAFER_SK128->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SAFER_SK128->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK128::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SAFER|http://en.wikipedia.org/wiki/SAFER>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SAFER_SK64.pm
Normal file
121
lib/Crypt/Cipher/SAFER_SK64.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SAFER_SK64;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SAFER_SK64 - Symetric cipher SAFER_SK64, key size: 64 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SAFER_SK64');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SAFER_SK64;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SAFER_SK64', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SAFER_SK64 cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SAFER_SK64->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SAFER_SK64->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SAFER_SK64::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SAFER|http://en.wikipedia.org/wiki/SAFER>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/SEED.pm
Normal file
121
lib/Crypt/Cipher/SEED.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::SEED;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::SEED - Symetric cipher SEED, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('SEED');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::SEED;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::SEED', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the SEED cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::SEED->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::SEED->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED->keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SEED->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::SEED::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::SEED::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SEED->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::SEED::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SEED|http://en.wikipedia.org/wiki/SEED>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Skipjack.pm
Normal file
121
lib/Crypt/Cipher/Skipjack.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Skipjack;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Skipjack - Symetric cipher Skipjack, key size: 80 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Skipjack');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Skipjack;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Skipjack', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Skipjack cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Skipjack->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Skipjack->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Skipjack::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Skipjack_(cipher)|http://en.wikipedia.org/wiki/Skipjack_(cipher)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/Twofish.pm
Normal file
121
lib/Crypt/Cipher/Twofish.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::Twofish;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::Twofish - Symetric cipher Twofish, key size: 128/192/256 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('Twofish');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::Twofish;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::Twofish', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the Twofish cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::Twofish->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::Twofish->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish->keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::Twofish::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Twofish->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::Twofish::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Twofish|http://en.wikipedia.org/wiki/Twofish>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
121
lib/Crypt/Cipher/XTEA.pm
Normal file
121
lib/Crypt/Cipher/XTEA.pm
Normal file
@ -0,0 +1,121 @@
|
||||
package Crypt::Cipher::XTEA;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use CryptX;
|
||||
use base 'Crypt::Cipher';
|
||||
|
||||
sub blocksize { Crypt::Cipher::blocksize(__PACKAGE__) }
|
||||
sub keysize { Crypt::Cipher::keysize(__PACKAGE__) }
|
||||
sub max_keysize { Crypt::Cipher::max_keysize(__PACKAGE__) }
|
||||
sub min_keysize { Crypt::Cipher::min_keysize(__PACKAGE__) }
|
||||
sub default_rounds { Crypt::Cipher::default_rounds(__PACKAGE__) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Cipher::XTEA - Symetric cipher XTEA, key size: 128 bits (Crypt::CBC compliant)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### example 1
|
||||
use Crypt::Mode::CBC;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::Mode::CBC->new('XTEA');
|
||||
my $ciphertext = $cbc->encrypt("secret data", $key, $iv);
|
||||
|
||||
### example 2
|
||||
use Crypt::CBC;
|
||||
use Crypt::Cipher::XTEA;
|
||||
|
||||
my $key = '...'; # length has to be valid key size for this cipher
|
||||
my $iv = '...'; # 16 bytes
|
||||
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::XTEA', -key=>$key, -iv=>$iv );
|
||||
my $ciphertext = $cbc->encrypt("secret data");
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module implements the XTEA cipher. Provided interface is compliant with L<Crypt::CBC|Crypt::CBC> module.
|
||||
|
||||
B<BEWARE:> This module implements just elementary "one-block-(en|de)cryption" operation - if you want to
|
||||
encrypt/decrypt generic data you have to use some of the cipher block modes - check for example
|
||||
L<Crypt::Mode::CBC|Crypt::Mode::CBC>, L<Crypt::Mode::CTR|Crypt::Mode::CTR> or L<Crypt::CBC|Crypt::CBC> (which will be slower).
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
$c = Crypt::Cipher::XTEA->new($key);
|
||||
#or
|
||||
$c = Crypt::Cipher::XTEA->new($key, $rounds);
|
||||
|
||||
=head2 encrypt
|
||||
|
||||
$ciphertext = $c->encrypt($plaintext);
|
||||
|
||||
=head2 decrypt
|
||||
|
||||
$plaintext = $c->decrypt($ciphertext);
|
||||
|
||||
=head2 keysize
|
||||
|
||||
$c->keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA->keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA::keysize;
|
||||
|
||||
=head2 blocksize
|
||||
|
||||
$c->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA->blocksize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA::blocksize;
|
||||
|
||||
=head2 max_keysize
|
||||
|
||||
$c->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA->max_keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA::max_keysize;
|
||||
|
||||
=head2 min_keysize
|
||||
|
||||
$c->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA->min_keysize;
|
||||
#or
|
||||
Crypt::Cipher::XTEA::min_keysize;
|
||||
|
||||
=head2 default_rounds
|
||||
|
||||
$c->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::XTEA->default_rounds;
|
||||
#or
|
||||
Crypt::Cipher::XTEA::default_rounds;
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Cipher|Crypt::Cipher>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/XTEA|http://en.wikipedia.org/wiki/XTEA>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
382
lib/Crypt/Digest.pm
Normal file
382
lib/Crypt/Digest.pm
Normal file
@ -0,0 +1,382 @@
|
||||
package Crypt::Digest;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
### the following methods/functions are implemented in XS:
|
||||
# - _new
|
||||
# - _hashsize
|
||||
# - _hashsize_by_name (function, not method)
|
||||
# - clone
|
||||
# - reset
|
||||
# - digest
|
||||
# - hexdigest
|
||||
# - b64digest
|
||||
# - add
|
||||
# - DESTROY
|
||||
|
||||
sub _trans_digest_name {
|
||||
my $name = shift;
|
||||
my %trans = (
|
||||
CHAES => 'chc_hash',
|
||||
RIPEMD128 => 'rmd128',
|
||||
RIPEMD160 => 'rmd160',
|
||||
RIPEMD256 => 'rmd256',
|
||||
RIPEMD320 => 'rmd320',
|
||||
TIGER192 => 'tiger',
|
||||
SHA512_224 => 'sha512-224',
|
||||
SHA512_256 => 'sha512-256',
|
||||
SHA3_224 => 'sha3-224',
|
||||
SHA3_256 => 'sha3-256',
|
||||
SHA3_384 => 'sha3-384',
|
||||
SHA3_512 => 'sha3-512',
|
||||
BLAKE2B_160 => 'blake2b-160',
|
||||
BLAKE2B_256 => 'blake2b-256',
|
||||
BLAKE2B_384 => 'blake2b-384',
|
||||
BLAKE2B_512 => 'blake2b-512',
|
||||
BLAKE2S_128 => 'blake2s-128',
|
||||
BLAKE2S_160 => 'blake2s-160',
|
||||
BLAKE2S_224 => 'blake2s-224',
|
||||
BLAKE2S_256 => 'blake2s-256',
|
||||
);
|
||||
$name =~ s/^Crypt::Digest:://i;
|
||||
return $trans{uc($name)} if defined $trans{uc($name)};
|
||||
return lc($name);
|
||||
}
|
||||
|
||||
### METHODS
|
||||
|
||||
sub new {
|
||||
my $pkg = shift;
|
||||
unshift @_, ($pkg eq 'Crypt::Digest' ? _trans_digest_name(shift) : _trans_digest_name($pkg));
|
||||
###return _new(@_);
|
||||
goto \&_new; # keep the real caller for croak()
|
||||
}
|
||||
|
||||
sub hashsize {
|
||||
return unless defined $_[0];
|
||||
|
||||
if (ref $_[0]) {
|
||||
###return _hashsize(@_);
|
||||
goto \&_hashsize if ref $_[0]; # keep the real caller for croak()
|
||||
}
|
||||
else {
|
||||
my $pkg = shift;
|
||||
unshift @_, ($pkg eq 'Crypt::Digest' ? _trans_digest_name(shift) : _trans_digest_name($pkg));
|
||||
###return _hashsize_by_name(@_);
|
||||
goto \&_hashsize_by_name; # keep the real caller for croak()
|
||||
}
|
||||
}
|
||||
|
||||
sub addfile {
|
||||
my ($self, $file) = @_;
|
||||
|
||||
my $handle;
|
||||
if (ref(\$file) eq 'SCALAR') { #filename
|
||||
open($handle, "<", $file) || croak "FATAL: cannot open '$file': $!";
|
||||
binmode($handle);
|
||||
}
|
||||
else { #handle
|
||||
$handle = $file
|
||||
}
|
||||
croak "FATAL: invalid handle" unless defined $handle;
|
||||
|
||||
my $n;
|
||||
my $buf = "";
|
||||
while (($n = read($handle, $buf, 32*1024))) {
|
||||
$self->add($buf)
|
||||
}
|
||||
croak "FATAL: read failed: $!" unless defined $n;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub CLONE_SKIP { 1 } # prevent cloning
|
||||
|
||||
### FUNCTIONS
|
||||
|
||||
sub digest_data { my $rv = eval {Crypt::Digest->new(shift)->add(@_)->digest}; _croak($@); $rv }
|
||||
sub digest_data_hex { my $rv = eval {Crypt::Digest->new(shift)->add(@_)->hexdigest}; _croak($@); $rv }
|
||||
sub digest_data_b64 { my $rv = eval {Crypt::Digest->new(shift)->add(@_)->b64digest}; _croak($@); $rv }
|
||||
sub digest_data_b64u { my $rv = eval {Crypt::Digest->new(shift)->add(@_)->b64udigest}; _croak($@); $rv }
|
||||
|
||||
sub digest_file { my $rv = eval {Crypt::Digest->new(shift)->addfile(@_)->digest}; _croak($@); $rv }
|
||||
sub digest_file_hex { my $rv = eval {Crypt::Digest->new(shift)->addfile(@_)->hexdigest}; _croak($@); $rv }
|
||||
sub digest_file_b64 { my $rv = eval {Crypt::Digest->new(shift)->addfile(@_)->b64digest}; _croak($@); $rv }
|
||||
sub digest_file_b64u { my $rv = eval {Crypt::Digest->new(shift)->addfile(@_)->b64udigest}; _croak($@); $rv }
|
||||
|
||||
sub _croak { #XXX-FIXME ugly hack for reporting real caller from XS croaks
|
||||
if ($_[0]) {
|
||||
$_[0] =~ s/ at .*?\.pm line \d+.[\n\r]*$//g;
|
||||
croak $_[0];
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest - Generic interface to hash/digest functions
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest qw( digest_data digest_data_hex digest_data_b64 digest_data_b64u
|
||||
digest_file digest_file_hex digest_file_b64 digest_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$digest_raw = digest_data('SHA1', 'data string');
|
||||
$digest_hex = digest_data_hex('SHA1', 'data string');
|
||||
$digest_b64 = digest_data_b64('SHA1', 'data string');
|
||||
$digest_b64u = digest_data_b64u('SHA1', 'data string');
|
||||
# calculate digest from file
|
||||
$digest_raw = digest_file('SHA1', 'filename.dat');
|
||||
$digest_hex = digest_file_hex('SHA1', 'filename.dat');
|
||||
$digest_b64 = digest_file_b64('SHA1', 'filename.dat');
|
||||
$digest_b64u = digest_file_b64u('SHA1', 'filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$digest_raw = digest_file('SHA1', *FILEHANDLE);
|
||||
$digest_hex = digest_file_hex('SHA1', *FILEHANDLE);
|
||||
$digest_b64 = digest_file_b64('SHA1', *FILEHANDLE);
|
||||
$digest_b64u = digest_file_b64u('SHA1', *FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest;
|
||||
|
||||
$d = Crypt::Digest->new('SHA1');
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to various hash/digest algorithms.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest qw( digest_data digest_data_hex digest_data_b64 digest_data_b64u
|
||||
digest_file digest_file_hex digest_file_b64 digest_file_b64u );
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
Please note that all functions take as its first argument the algoritm name, supported values are:
|
||||
|
||||
'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160',
|
||||
'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256',
|
||||
'SHA384', 'SHA512', 'SHA512_224', 'SHA512_256', 'Tiger192', 'Whirlpool',
|
||||
'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512'
|
||||
|
||||
(simply any <FUNCNAME> for which there is Crypt::Digest::<FUNCNAME> module)
|
||||
|
||||
=head2 digest_data
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a binary string.
|
||||
|
||||
$digest_raw = digest_data('SHA1', 'data string');
|
||||
#or
|
||||
$digest_raw = digest_data('SHA1', 'any data', 'more data', 'even more data');
|
||||
|
||||
=head2 digest_data_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a hexadecimal string.
|
||||
|
||||
$digest_hex = digest_data_hex('SHA1', 'data string');
|
||||
#or
|
||||
$digest_hex = digest_data_hex('SHA1', 'any data', 'more data', 'even more data');
|
||||
|
||||
=head2 digest_data_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$digest_b64 = digest_data_b64('SHA1', 'data string');
|
||||
#or
|
||||
$digest_b64 = digest_data_b64('SHA1', 'any data', 'more data', 'even more data');
|
||||
|
||||
=head2 digest_data_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$digest_b64url = digest_data_b64u('SHA1', 'data string');
|
||||
#or
|
||||
$digest_b64url = digest_data_b64u('SHA1', 'any data', 'more data', 'even more data');
|
||||
|
||||
=head2 digest_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its digest encoded as a binary string.
|
||||
|
||||
$digest_raw = digest_file('SHA1', 'filename.dat');
|
||||
#or
|
||||
$digest_raw = digest_file('SHA1', *FILEHANDLE);
|
||||
|
||||
=head2 digest_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its digest encoded as a hexadecimal string.
|
||||
|
||||
$digest_hex = digest_file_hex('SHA1', 'filename.dat');
|
||||
#or
|
||||
$digest_hex = digest_file_hex('SHA1', *FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 digest_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$digest_b64 = digest_file_b64('SHA1', 'filename.dat');
|
||||
#or
|
||||
$digest_b64 = digest_file_b64('SHA1', *FILEHANDLE);
|
||||
|
||||
=head2 digest_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$digest_b64url = digest_file_b64u('SHA1', 'filename.dat');
|
||||
#or
|
||||
$digest_b64url = digest_file_b64u('SHA1', *FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Constructor, returns a reference to the digest object.
|
||||
|
||||
$d = Crypt::Digest->new($name);
|
||||
# $name could be: 'CHAES', 'MD2', 'MD4', 'MD5', 'RIPEMD128', 'RIPEMD160',
|
||||
# 'RIPEMD256', 'RIPEMD320', 'SHA1', 'SHA224', 'SHA256', 'SHA384',
|
||||
# 'SHA512', 'SHA512_224', 'SHA512_256', 'Tiger192', 'Whirlpool'
|
||||
#
|
||||
# simply any <FUNCNAME> for which there is Crypt::Digest::<FUNCNAME> module
|
||||
|
||||
=head2 clone
|
||||
|
||||
Creates a copy of the digest object state and returns a reference to the copy.
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
Reinitialize the digest object state and returns a reference to the digest object.
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
All arguments are appended to the message we calculate digest for.
|
||||
The return value is the digest object itself.
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
Note that all the following cases are equivalent:
|
||||
|
||||
# case 1
|
||||
$d->add('aa', 'bb', 'cc');
|
||||
|
||||
# case 2
|
||||
$d->add('aa');
|
||||
$d->add('bb');
|
||||
$d->add('cc');
|
||||
|
||||
# case 3
|
||||
$d->add('aabbcc');
|
||||
|
||||
# case 4
|
||||
$d->add('aa')->add('bb')->add('cc');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
The content of the file (or filehandle) is appended to the message we calculate digest for.
|
||||
The return value is the digest object itself.
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
This method is available mostly for compatibility with other Digest::SOMETHING modules on CPAN, you are very unlikely to need it.
|
||||
The return value is the digest object itself.
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
B<BEWARE:> It is not possible to add bits that are not a multiple of 8.
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
Returns the length of calculated digest in bytes (e.g. 32 for SHA-256).
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest->hashsize('SHA1');
|
||||
#or
|
||||
Crypt::Digest::hashsize('SHA1');
|
||||
|
||||
=head2 digest
|
||||
|
||||
Returns the binary digest (raw bytes).
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
Returns the digest encoded as a hexadecimal string.
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
Returns the digest encoded as a Base64 string, B<with> trailing '=' padding (B<BEWARE:> this padding
|
||||
style might differ from other Digest::SOMETHING modules on CPAN).
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
Returns the digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>
|
||||
|
||||
=item * L<Crypt::Digest|Crypt::Digest> tries to be compatible with L<Digest|Digest> interface.
|
||||
|
||||
=item * Check subclasses like L<Crypt::Digest::SHA1|Crypt::Digest::SHA1>, L<Crypt::Digest::MD5|Crypt::Digest::MD5>, ...
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2b_160.pm
Normal file
229
lib/Crypt/Digest/BLAKE2b_160.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2b_160;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2b_160 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2b_160_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_160_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_160_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2b_160_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2b_160_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_160_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_160_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2b_160 - Hash function BLAKE2b [size: 160 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2b_160 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2b_160_raw = blake2b_160('data string');
|
||||
$blake2b_160_hex = blake2b_160_hex('data string');
|
||||
$blake2b_160_b64 = blake2b_160_b64('data string');
|
||||
$blake2b_160_b64u = blake2b_160_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2b_160_raw = blake2b_160_file('filename.dat');
|
||||
$blake2b_160_hex = blake2b_160_file_hex('filename.dat');
|
||||
$blake2b_160_b64 = blake2b_160_file_b64('filename.dat');
|
||||
$blake2b_160_b64u = blake2b_160_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2b_160_raw = blake2b_160_file(*FILEHANDLE);
|
||||
$blake2b_160_hex = blake2b_160_file_hex(*FILEHANDLE);
|
||||
$blake2b_160_b64 = blake2b_160_file_b64(*FILEHANDLE);
|
||||
$blake2b_160_b64u = blake2b_160_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2b_160;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_160->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2b_160 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_160 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_160 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2b_160
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_160 digest encoded as a binary string.
|
||||
|
||||
$blake2b_160_raw = blake2b_160('data string');
|
||||
#or
|
||||
$blake2b_160_raw = blake2b_160('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_160_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_160 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_160_hex = blake2b_160_hex('data string');
|
||||
#or
|
||||
$blake2b_160_hex = blake2b_160_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_160_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_160_b64 = blake2b_160_b64('data string');
|
||||
#or
|
||||
$blake2b_160_b64 = blake2b_160_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_160_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_160_b64url = blake2b_160_b64u('data string');
|
||||
#or
|
||||
$blake2b_160_b64url = blake2b_160_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_160_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_160 digest encoded as a binary string.
|
||||
|
||||
$blake2b_160_raw = blake2b_160_file('filename.dat');
|
||||
#or
|
||||
$blake2b_160_raw = blake2b_160_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_160_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_160 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_160_hex = blake2b_160_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2b_160_hex = blake2b_160_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2b_160_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_160_b64 = blake2b_160_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2b_160_b64 = blake2b_160_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_160_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_160_b64url = blake2b_160_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2b_160_b64url = blake2b_160_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_160->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_160->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_160::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2b_256.pm
Normal file
229
lib/Crypt/Digest/BLAKE2b_256.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2b_256;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2b_256 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2b_256_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_256_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_256_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2b_256_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2b_256_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_256_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_256_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2b_256 - Hash function BLAKE2b [size: 256 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2b_256 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2b_256_raw = blake2b_256('data string');
|
||||
$blake2b_256_hex = blake2b_256_hex('data string');
|
||||
$blake2b_256_b64 = blake2b_256_b64('data string');
|
||||
$blake2b_256_b64u = blake2b_256_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2b_256_raw = blake2b_256_file('filename.dat');
|
||||
$blake2b_256_hex = blake2b_256_file_hex('filename.dat');
|
||||
$blake2b_256_b64 = blake2b_256_file_b64('filename.dat');
|
||||
$blake2b_256_b64u = blake2b_256_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2b_256_raw = blake2b_256_file(*FILEHANDLE);
|
||||
$blake2b_256_hex = blake2b_256_file_hex(*FILEHANDLE);
|
||||
$blake2b_256_b64 = blake2b_256_file_b64(*FILEHANDLE);
|
||||
$blake2b_256_b64u = blake2b_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2b_256;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_256->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2b_256 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_256 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_256 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2b_256
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_256 digest encoded as a binary string.
|
||||
|
||||
$blake2b_256_raw = blake2b_256('data string');
|
||||
#or
|
||||
$blake2b_256_raw = blake2b_256('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_256_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_256_hex = blake2b_256_hex('data string');
|
||||
#or
|
||||
$blake2b_256_hex = blake2b_256_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_256_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_256_b64 = blake2b_256_b64('data string');
|
||||
#or
|
||||
$blake2b_256_b64 = blake2b_256_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_256_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_256_b64url = blake2b_256_b64u('data string');
|
||||
#or
|
||||
$blake2b_256_b64url = blake2b_256_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_256_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_256 digest encoded as a binary string.
|
||||
|
||||
$blake2b_256_raw = blake2b_256_file('filename.dat');
|
||||
#or
|
||||
$blake2b_256_raw = blake2b_256_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_256_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_256_hex = blake2b_256_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2b_256_hex = blake2b_256_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2b_256_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_256_b64 = blake2b_256_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2b_256_b64 = blake2b_256_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_256_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_256_b64url = blake2b_256_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2b_256_b64url = blake2b_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_256->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_256->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_256::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2b_384.pm
Normal file
229
lib/Crypt/Digest/BLAKE2b_384.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2b_384;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2b_384 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2b_384_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_384_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_384_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2b_384_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2b_384_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_384_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_384_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2b_384 - Hash function BLAKE2b [size: 384 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2b_384 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2b_384_raw = blake2b_384('data string');
|
||||
$blake2b_384_hex = blake2b_384_hex('data string');
|
||||
$blake2b_384_b64 = blake2b_384_b64('data string');
|
||||
$blake2b_384_b64u = blake2b_384_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2b_384_raw = blake2b_384_file('filename.dat');
|
||||
$blake2b_384_hex = blake2b_384_file_hex('filename.dat');
|
||||
$blake2b_384_b64 = blake2b_384_file_b64('filename.dat');
|
||||
$blake2b_384_b64u = blake2b_384_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2b_384_raw = blake2b_384_file(*FILEHANDLE);
|
||||
$blake2b_384_hex = blake2b_384_file_hex(*FILEHANDLE);
|
||||
$blake2b_384_b64 = blake2b_384_file_b64(*FILEHANDLE);
|
||||
$blake2b_384_b64u = blake2b_384_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2b_384;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_384->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2b_384 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_384 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_384 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2b_384
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_384 digest encoded as a binary string.
|
||||
|
||||
$blake2b_384_raw = blake2b_384('data string');
|
||||
#or
|
||||
$blake2b_384_raw = blake2b_384('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_384_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_384 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_384_hex = blake2b_384_hex('data string');
|
||||
#or
|
||||
$blake2b_384_hex = blake2b_384_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_384_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_384_b64 = blake2b_384_b64('data string');
|
||||
#or
|
||||
$blake2b_384_b64 = blake2b_384_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_384_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_384_b64url = blake2b_384_b64u('data string');
|
||||
#or
|
||||
$blake2b_384_b64url = blake2b_384_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_384_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_384 digest encoded as a binary string.
|
||||
|
||||
$blake2b_384_raw = blake2b_384_file('filename.dat');
|
||||
#or
|
||||
$blake2b_384_raw = blake2b_384_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_384_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_384 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_384_hex = blake2b_384_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2b_384_hex = blake2b_384_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2b_384_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_384_b64 = blake2b_384_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2b_384_b64 = blake2b_384_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_384_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_384_b64url = blake2b_384_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2b_384_b64url = blake2b_384_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_384->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_384->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_384::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2b_512.pm
Normal file
229
lib/Crypt/Digest/BLAKE2b_512.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2b_512;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2b_512 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2b_512_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_512_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_512_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2b_512_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2b_512_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2b_512_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2b_512_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2b_512 - Hash function BLAKE2b [size: 512 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2b_512 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2b_512_raw = blake2b_512('data string');
|
||||
$blake2b_512_hex = blake2b_512_hex('data string');
|
||||
$blake2b_512_b64 = blake2b_512_b64('data string');
|
||||
$blake2b_512_b64u = blake2b_512_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2b_512_raw = blake2b_512_file('filename.dat');
|
||||
$blake2b_512_hex = blake2b_512_file_hex('filename.dat');
|
||||
$blake2b_512_b64 = blake2b_512_file_b64('filename.dat');
|
||||
$blake2b_512_b64u = blake2b_512_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2b_512_raw = blake2b_512_file(*FILEHANDLE);
|
||||
$blake2b_512_hex = blake2b_512_file_hex(*FILEHANDLE);
|
||||
$blake2b_512_b64 = blake2b_512_file_b64(*FILEHANDLE);
|
||||
$blake2b_512_b64u = blake2b_512_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2b_512;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_512->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2b_512 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_512 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2b_512 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2b_512
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_512 digest encoded as a binary string.
|
||||
|
||||
$blake2b_512_raw = blake2b_512('data string');
|
||||
#or
|
||||
$blake2b_512_raw = blake2b_512('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_512_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_512 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_512_hex = blake2b_512_hex('data string');
|
||||
#or
|
||||
$blake2b_512_hex = blake2b_512_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_512_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_512 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_512_b64 = blake2b_512_b64('data string');
|
||||
#or
|
||||
$blake2b_512_b64 = blake2b_512_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_512_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2b_512 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_512_b64url = blake2b_512_b64u('data string');
|
||||
#or
|
||||
$blake2b_512_b64url = blake2b_512_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2b_512_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_512 digest encoded as a binary string.
|
||||
|
||||
$blake2b_512_raw = blake2b_512_file('filename.dat');
|
||||
#or
|
||||
$blake2b_512_raw = blake2b_512_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_512_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_512 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2b_512_hex = blake2b_512_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2b_512_hex = blake2b_512_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2b_512_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_512 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2b_512_b64 = blake2b_512_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2b_512_b64 = blake2b_512_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2b_512_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2b_512 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2b_512_b64url = blake2b_512_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2b_512_b64url = blake2b_512_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2b_512->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_512->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2b_512::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2s_128.pm
Normal file
229
lib/Crypt/Digest/BLAKE2s_128.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2s_128;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2s_128 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2s_128_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_128_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_128_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2s_128_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2s_128_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_128_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_128_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2s_128 - Hash function BLAKE2s [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2s_128 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2s_128_raw = blake2s_128('data string');
|
||||
$blake2s_128_hex = blake2s_128_hex('data string');
|
||||
$blake2s_128_b64 = blake2s_128_b64('data string');
|
||||
$blake2s_128_b64u = blake2s_128_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2s_128_raw = blake2s_128_file('filename.dat');
|
||||
$blake2s_128_hex = blake2s_128_file_hex('filename.dat');
|
||||
$blake2s_128_b64 = blake2s_128_file_b64('filename.dat');
|
||||
$blake2s_128_b64u = blake2s_128_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2s_128_raw = blake2s_128_file(*FILEHANDLE);
|
||||
$blake2s_128_hex = blake2s_128_file_hex(*FILEHANDLE);
|
||||
$blake2s_128_b64 = blake2s_128_file_b64(*FILEHANDLE);
|
||||
$blake2s_128_b64u = blake2s_128_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2s_128;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_128->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2s_128 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_128 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_128 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2s_128
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_128 digest encoded as a binary string.
|
||||
|
||||
$blake2s_128_raw = blake2s_128('data string');
|
||||
#or
|
||||
$blake2s_128_raw = blake2s_128('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_128_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_128 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_128_hex = blake2s_128_hex('data string');
|
||||
#or
|
||||
$blake2s_128_hex = blake2s_128_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_128_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_128 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_128_b64 = blake2s_128_b64('data string');
|
||||
#or
|
||||
$blake2s_128_b64 = blake2s_128_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_128_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_128 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_128_b64url = blake2s_128_b64u('data string');
|
||||
#or
|
||||
$blake2s_128_b64url = blake2s_128_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_128_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_128 digest encoded as a binary string.
|
||||
|
||||
$blake2s_128_raw = blake2s_128_file('filename.dat');
|
||||
#or
|
||||
$blake2s_128_raw = blake2s_128_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_128_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_128 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_128_hex = blake2s_128_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2s_128_hex = blake2s_128_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2s_128_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_128 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_128_b64 = blake2s_128_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2s_128_b64 = blake2s_128_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_128_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_128 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_128_b64url = blake2s_128_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2s_128_b64url = blake2s_128_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_128->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_128->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_128::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2s_160.pm
Normal file
229
lib/Crypt/Digest/BLAKE2s_160.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2s_160;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2s_160 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2s_160_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_160_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_160_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2s_160_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2s_160_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_160_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_160_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2s_160 - Hash function BLAKE2s [size: 160 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2s_160 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2s_160_raw = blake2s_160('data string');
|
||||
$blake2s_160_hex = blake2s_160_hex('data string');
|
||||
$blake2s_160_b64 = blake2s_160_b64('data string');
|
||||
$blake2s_160_b64u = blake2s_160_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2s_160_raw = blake2s_160_file('filename.dat');
|
||||
$blake2s_160_hex = blake2s_160_file_hex('filename.dat');
|
||||
$blake2s_160_b64 = blake2s_160_file_b64('filename.dat');
|
||||
$blake2s_160_b64u = blake2s_160_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2s_160_raw = blake2s_160_file(*FILEHANDLE);
|
||||
$blake2s_160_hex = blake2s_160_file_hex(*FILEHANDLE);
|
||||
$blake2s_160_b64 = blake2s_160_file_b64(*FILEHANDLE);
|
||||
$blake2s_160_b64u = blake2s_160_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2s_160;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_160->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2s_160 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_160 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_160 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2s_160
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_160 digest encoded as a binary string.
|
||||
|
||||
$blake2s_160_raw = blake2s_160('data string');
|
||||
#or
|
||||
$blake2s_160_raw = blake2s_160('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_160_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_160 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_160_hex = blake2s_160_hex('data string');
|
||||
#or
|
||||
$blake2s_160_hex = blake2s_160_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_160_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_160_b64 = blake2s_160_b64('data string');
|
||||
#or
|
||||
$blake2s_160_b64 = blake2s_160_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_160_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_160_b64url = blake2s_160_b64u('data string');
|
||||
#or
|
||||
$blake2s_160_b64url = blake2s_160_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_160_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_160 digest encoded as a binary string.
|
||||
|
||||
$blake2s_160_raw = blake2s_160_file('filename.dat');
|
||||
#or
|
||||
$blake2s_160_raw = blake2s_160_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_160_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_160 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_160_hex = blake2s_160_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2s_160_hex = blake2s_160_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2s_160_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_160_b64 = blake2s_160_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2s_160_b64 = blake2s_160_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_160_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_160_b64url = blake2s_160_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2s_160_b64url = blake2s_160_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_160->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_160->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_160::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2s_224.pm
Normal file
229
lib/Crypt/Digest/BLAKE2s_224.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2s_224;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2s_224 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2s_224_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_224_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_224_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2s_224_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2s_224_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_224_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_224_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2s_224 - Hash function BLAKE2s [size: 224 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2s_224 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2s_224_raw = blake2s_224('data string');
|
||||
$blake2s_224_hex = blake2s_224_hex('data string');
|
||||
$blake2s_224_b64 = blake2s_224_b64('data string');
|
||||
$blake2s_224_b64u = blake2s_224_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2s_224_raw = blake2s_224_file('filename.dat');
|
||||
$blake2s_224_hex = blake2s_224_file_hex('filename.dat');
|
||||
$blake2s_224_b64 = blake2s_224_file_b64('filename.dat');
|
||||
$blake2s_224_b64u = blake2s_224_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2s_224_raw = blake2s_224_file(*FILEHANDLE);
|
||||
$blake2s_224_hex = blake2s_224_file_hex(*FILEHANDLE);
|
||||
$blake2s_224_b64 = blake2s_224_file_b64(*FILEHANDLE);
|
||||
$blake2s_224_b64u = blake2s_224_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2s_224;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_224->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2s_224 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_224 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_224 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2s_224
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_224 digest encoded as a binary string.
|
||||
|
||||
$blake2s_224_raw = blake2s_224('data string');
|
||||
#or
|
||||
$blake2s_224_raw = blake2s_224('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_224_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_224 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_224_hex = blake2s_224_hex('data string');
|
||||
#or
|
||||
$blake2s_224_hex = blake2s_224_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_224_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_224_b64 = blake2s_224_b64('data string');
|
||||
#or
|
||||
$blake2s_224_b64 = blake2s_224_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_224_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_224_b64url = blake2s_224_b64u('data string');
|
||||
#or
|
||||
$blake2s_224_b64url = blake2s_224_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_224_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_224 digest encoded as a binary string.
|
||||
|
||||
$blake2s_224_raw = blake2s_224_file('filename.dat');
|
||||
#or
|
||||
$blake2s_224_raw = blake2s_224_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_224_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_224 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_224_hex = blake2s_224_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2s_224_hex = blake2s_224_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2s_224_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_224_b64 = blake2s_224_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2s_224_b64 = blake2s_224_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_224_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_224_b64url = blake2s_224_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2s_224_b64url = blake2s_224_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_224->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_224->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_224::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
229
lib/Crypt/Digest/BLAKE2s_256.pm
Normal file
229
lib/Crypt/Digest/BLAKE2s_256.pm
Normal file
@ -0,0 +1,229 @@
|
||||
package Crypt::Digest::BLAKE2s_256;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub blake2s_256 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub blake2s_256_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_256_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_256_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub blake2s_256_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub blake2s_256_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub blake2s_256_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub blake2s_256_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::BLAKE2s_256 - Hash function BLAKE2s [size: 256 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::BLAKE2s_256 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$blake2s_256_raw = blake2s_256('data string');
|
||||
$blake2s_256_hex = blake2s_256_hex('data string');
|
||||
$blake2s_256_b64 = blake2s_256_b64('data string');
|
||||
$blake2s_256_b64u = blake2s_256_b64u('data string');
|
||||
# calculate digest from file
|
||||
$blake2s_256_raw = blake2s_256_file('filename.dat');
|
||||
$blake2s_256_hex = blake2s_256_file_hex('filename.dat');
|
||||
$blake2s_256_b64 = blake2s_256_file_b64('filename.dat');
|
||||
$blake2s_256_b64u = blake2s_256_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$blake2s_256_raw = blake2s_256_file(*FILEHANDLE);
|
||||
$blake2s_256_hex = blake2s_256_file_hex(*FILEHANDLE);
|
||||
$blake2s_256_b64 = blake2s_256_file_b64(*FILEHANDLE);
|
||||
$blake2s_256_b64u = blake2s_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::BLAKE2s_256;
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_256->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the BLAKE2s_256 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_256 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::BLAKE2s_256 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 blake2s_256
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_256 digest encoded as a binary string.
|
||||
|
||||
$blake2s_256_raw = blake2s_256('data string');
|
||||
#or
|
||||
$blake2s_256_raw = blake2s_256('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_256_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_256_hex = blake2s_256_hex('data string');
|
||||
#or
|
||||
$blake2s_256_hex = blake2s_256_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_256_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_256_b64 = blake2s_256_b64('data string');
|
||||
#or
|
||||
$blake2s_256_b64 = blake2s_256_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_256_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its BLAKE2s_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_256_b64url = blake2s_256_b64u('data string');
|
||||
#or
|
||||
$blake2s_256_b64url = blake2s_256_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 blake2s_256_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_256 digest encoded as a binary string.
|
||||
|
||||
$blake2s_256_raw = blake2s_256_file('filename.dat');
|
||||
#or
|
||||
$blake2s_256_raw = blake2s_256_file(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_256_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$blake2s_256_hex = blake2s_256_file_hex('filename.dat');
|
||||
#or
|
||||
$blake2s_256_hex = blake2s_256_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 blake2s_256_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$blake2s_256_b64 = blake2s_256_file_b64('filename.dat');
|
||||
#or
|
||||
$blake2s_256_b64 = blake2s_256_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 blake2s_256_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its BLAKE2s_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$blake2s_256_b64url = blake2s_256_file_b64u('filename.dat');
|
||||
#or
|
||||
$blake2s_256_b64url = blake2s_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::BLAKE2s_256->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_256->hashsize();
|
||||
#or
|
||||
Crypt::Digest::BLAKE2s_256::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<https://blake2.net/|https://blake2.net/>
|
||||
|
||||
=item * L<https://tools.ietf.org/html/rfc7693|https://tools.ietf.org/html/rfc7693>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/CHAES.pm
Normal file
227
lib/Crypt/Digest/CHAES.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::CHAES;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( chaes chaes_hex chaes_b64 chaes_b64u chaes_file chaes_file_hex chaes_file_b64 chaes_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub chaes { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub chaes_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub chaes_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub chaes_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub chaes_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub chaes_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub chaes_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub chaes_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::CHAES - Hash function - CipherHash based on AES [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::CHAES qw( chaes chaes_hex chaes_b64 chaes_b64u
|
||||
chaes_file chaes_file_hex chaes_file_b64 chaes_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$chaes_raw = chaes('data string');
|
||||
$chaes_hex = chaes_hex('data string');
|
||||
$chaes_b64 = chaes_b64('data string');
|
||||
$chaes_b64u = chaes_b64u('data string');
|
||||
# calculate digest from file
|
||||
$chaes_raw = chaes_file('filename.dat');
|
||||
$chaes_hex = chaes_file_hex('filename.dat');
|
||||
$chaes_b64 = chaes_file_b64('filename.dat');
|
||||
$chaes_b64u = chaes_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$chaes_raw = chaes_file(*FILEHANDLE);
|
||||
$chaes_hex = chaes_file_hex(*FILEHANDLE);
|
||||
$chaes_b64 = chaes_file_b64(*FILEHANDLE);
|
||||
$chaes_b64u = chaes_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::CHAES;
|
||||
|
||||
$d = Crypt::Digest::CHAES->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the CHAES digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::CHAES qw(chaes chaes_hex chaes_b64 chaes_b64u
|
||||
chaes_file chaes_file_hex chaes_file_b64 chaes_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::CHAES ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 chaes
|
||||
|
||||
Logically joins all arguments into a single string, and returns its CHAES digest encoded as a binary string.
|
||||
|
||||
$chaes_raw = chaes('data string');
|
||||
#or
|
||||
$chaes_raw = chaes('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 chaes_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its CHAES digest encoded as a hexadecimal string.
|
||||
|
||||
$chaes_hex = chaes_hex('data string');
|
||||
#or
|
||||
$chaes_hex = chaes_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 chaes_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its CHAES digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$chaes_b64 = chaes_b64('data string');
|
||||
#or
|
||||
$chaes_b64 = chaes_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 chaes_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its CHAES digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$chaes_b64url = chaes_b64u('data string');
|
||||
#or
|
||||
$chaes_b64url = chaes_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 chaes_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its CHAES digest encoded as a binary string.
|
||||
|
||||
$chaes_raw = chaes_file('filename.dat');
|
||||
#or
|
||||
$chaes_raw = chaes_file(*FILEHANDLE);
|
||||
|
||||
=head2 chaes_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its CHAES digest encoded as a hexadecimal string.
|
||||
|
||||
$chaes_hex = chaes_file_hex('filename.dat');
|
||||
#or
|
||||
$chaes_hex = chaes_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 chaes_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its CHAES digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$chaes_b64 = chaes_file_b64('filename.dat');
|
||||
#or
|
||||
$chaes_b64 = chaes_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 chaes_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its CHAES digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$chaes_b64url = chaes_file_b64u('filename.dat');
|
||||
#or
|
||||
$chaes_b64url = chaes_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::CHAES->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::CHAES->hashsize();
|
||||
#or
|
||||
Crypt::Digest::CHAES::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/Cryptographic_hash_function#Hash_functions_based_on_block_ciphers|http://en.wikipedia.org/wiki/Cryptographic_hash_function#Hash_functions_based_on_block_ciphers>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/MD2.pm
Normal file
227
lib/Crypt/Digest/MD2.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::MD2;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( md2 md2_hex md2_b64 md2_b64u md2_file md2_file_hex md2_file_b64 md2_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub md2 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub md2_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub md2_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub md2_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub md2_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub md2_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub md2_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub md2_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::MD2 - Hash function MD2 [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::MD2 qw( md2 md2_hex md2_b64 md2_b64u
|
||||
md2_file md2_file_hex md2_file_b64 md2_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$md2_raw = md2('data string');
|
||||
$md2_hex = md2_hex('data string');
|
||||
$md2_b64 = md2_b64('data string');
|
||||
$md2_b64u = md2_b64u('data string');
|
||||
# calculate digest from file
|
||||
$md2_raw = md2_file('filename.dat');
|
||||
$md2_hex = md2_file_hex('filename.dat');
|
||||
$md2_b64 = md2_file_b64('filename.dat');
|
||||
$md2_b64u = md2_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$md2_raw = md2_file(*FILEHANDLE);
|
||||
$md2_hex = md2_file_hex(*FILEHANDLE);
|
||||
$md2_b64 = md2_file_b64(*FILEHANDLE);
|
||||
$md2_b64u = md2_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::MD2;
|
||||
|
||||
$d = Crypt::Digest::MD2->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the MD2 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::MD2 qw(md2 md2_hex md2_b64 md2_b64u
|
||||
md2_file md2_file_hex md2_file_b64 md2_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::MD2 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 md2
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD2 digest encoded as a binary string.
|
||||
|
||||
$md2_raw = md2('data string');
|
||||
#or
|
||||
$md2_raw = md2('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md2_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD2 digest encoded as a hexadecimal string.
|
||||
|
||||
$md2_hex = md2_hex('data string');
|
||||
#or
|
||||
$md2_hex = md2_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md2_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD2 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md2_b64 = md2_b64('data string');
|
||||
#or
|
||||
$md2_b64 = md2_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md2_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD2 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md2_b64url = md2_b64u('data string');
|
||||
#or
|
||||
$md2_b64url = md2_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md2_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD2 digest encoded as a binary string.
|
||||
|
||||
$md2_raw = md2_file('filename.dat');
|
||||
#or
|
||||
$md2_raw = md2_file(*FILEHANDLE);
|
||||
|
||||
=head2 md2_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD2 digest encoded as a hexadecimal string.
|
||||
|
||||
$md2_hex = md2_file_hex('filename.dat');
|
||||
#or
|
||||
$md2_hex = md2_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 md2_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD2 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md2_b64 = md2_file_b64('filename.dat');
|
||||
#or
|
||||
$md2_b64 = md2_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 md2_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD2 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md2_b64url = md2_file_b64u('filename.dat');
|
||||
#or
|
||||
$md2_b64url = md2_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::MD2->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::MD2->hashsize();
|
||||
#or
|
||||
Crypt::Digest::MD2::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/MD2_(cryptography)|http://en.wikipedia.org/wiki/MD2_(cryptography)>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/MD4.pm
Normal file
227
lib/Crypt/Digest/MD4.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::MD4;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( md4 md4_hex md4_b64 md4_b64u md4_file md4_file_hex md4_file_b64 md4_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub md4 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub md4_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub md4_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub md4_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub md4_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub md4_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub md4_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub md4_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::MD4 - Hash function MD4 [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::MD4 qw( md4 md4_hex md4_b64 md4_b64u
|
||||
md4_file md4_file_hex md4_file_b64 md4_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$md4_raw = md4('data string');
|
||||
$md4_hex = md4_hex('data string');
|
||||
$md4_b64 = md4_b64('data string');
|
||||
$md4_b64u = md4_b64u('data string');
|
||||
# calculate digest from file
|
||||
$md4_raw = md4_file('filename.dat');
|
||||
$md4_hex = md4_file_hex('filename.dat');
|
||||
$md4_b64 = md4_file_b64('filename.dat');
|
||||
$md4_b64u = md4_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$md4_raw = md4_file(*FILEHANDLE);
|
||||
$md4_hex = md4_file_hex(*FILEHANDLE);
|
||||
$md4_b64 = md4_file_b64(*FILEHANDLE);
|
||||
$md4_b64u = md4_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::MD4;
|
||||
|
||||
$d = Crypt::Digest::MD4->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the MD4 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::MD4 qw(md4 md4_hex md4_b64 md4_b64u
|
||||
md4_file md4_file_hex md4_file_b64 md4_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::MD4 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 md4
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD4 digest encoded as a binary string.
|
||||
|
||||
$md4_raw = md4('data string');
|
||||
#or
|
||||
$md4_raw = md4('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md4_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD4 digest encoded as a hexadecimal string.
|
||||
|
||||
$md4_hex = md4_hex('data string');
|
||||
#or
|
||||
$md4_hex = md4_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md4_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD4 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md4_b64 = md4_b64('data string');
|
||||
#or
|
||||
$md4_b64 = md4_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md4_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD4 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md4_b64url = md4_b64u('data string');
|
||||
#or
|
||||
$md4_b64url = md4_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md4_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD4 digest encoded as a binary string.
|
||||
|
||||
$md4_raw = md4_file('filename.dat');
|
||||
#or
|
||||
$md4_raw = md4_file(*FILEHANDLE);
|
||||
|
||||
=head2 md4_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD4 digest encoded as a hexadecimal string.
|
||||
|
||||
$md4_hex = md4_file_hex('filename.dat');
|
||||
#or
|
||||
$md4_hex = md4_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 md4_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD4 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md4_b64 = md4_file_b64('filename.dat');
|
||||
#or
|
||||
$md4_b64 = md4_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 md4_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD4 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md4_b64url = md4_file_b64u('filename.dat');
|
||||
#or
|
||||
$md4_b64url = md4_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::MD4->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::MD4->hashsize();
|
||||
#or
|
||||
Crypt::Digest::MD4::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/MD4|http://en.wikipedia.org/wiki/MD4>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/MD5.pm
Normal file
227
lib/Crypt/Digest/MD5.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::MD5;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( md5 md5_hex md5_b64 md5_b64u md5_file md5_file_hex md5_file_b64 md5_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub md5 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub md5_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub md5_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub md5_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub md5_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub md5_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub md5_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub md5_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::MD5 - Hash function MD5 [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::MD5 qw( md5 md5_hex md5_b64 md5_b64u
|
||||
md5_file md5_file_hex md5_file_b64 md5_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$md5_raw = md5('data string');
|
||||
$md5_hex = md5_hex('data string');
|
||||
$md5_b64 = md5_b64('data string');
|
||||
$md5_b64u = md5_b64u('data string');
|
||||
# calculate digest from file
|
||||
$md5_raw = md5_file('filename.dat');
|
||||
$md5_hex = md5_file_hex('filename.dat');
|
||||
$md5_b64 = md5_file_b64('filename.dat');
|
||||
$md5_b64u = md5_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$md5_raw = md5_file(*FILEHANDLE);
|
||||
$md5_hex = md5_file_hex(*FILEHANDLE);
|
||||
$md5_b64 = md5_file_b64(*FILEHANDLE);
|
||||
$md5_b64u = md5_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::MD5;
|
||||
|
||||
$d = Crypt::Digest::MD5->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the MD5 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::MD5 qw(md5 md5_hex md5_b64 md5_b64u
|
||||
md5_file md5_file_hex md5_file_b64 md5_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::MD5 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 md5
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD5 digest encoded as a binary string.
|
||||
|
||||
$md5_raw = md5('data string');
|
||||
#or
|
||||
$md5_raw = md5('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md5_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD5 digest encoded as a hexadecimal string.
|
||||
|
||||
$md5_hex = md5_hex('data string');
|
||||
#or
|
||||
$md5_hex = md5_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md5_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD5 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md5_b64 = md5_b64('data string');
|
||||
#or
|
||||
$md5_b64 = md5_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md5_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its MD5 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md5_b64url = md5_b64u('data string');
|
||||
#or
|
||||
$md5_b64url = md5_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 md5_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD5 digest encoded as a binary string.
|
||||
|
||||
$md5_raw = md5_file('filename.dat');
|
||||
#or
|
||||
$md5_raw = md5_file(*FILEHANDLE);
|
||||
|
||||
=head2 md5_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD5 digest encoded as a hexadecimal string.
|
||||
|
||||
$md5_hex = md5_file_hex('filename.dat');
|
||||
#or
|
||||
$md5_hex = md5_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 md5_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD5 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$md5_b64 = md5_file_b64('filename.dat');
|
||||
#or
|
||||
$md5_b64 = md5_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 md5_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its MD5 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$md5_b64url = md5_file_b64u('filename.dat');
|
||||
#or
|
||||
$md5_b64url = md5_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::MD5->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::MD5->hashsize();
|
||||
#or
|
||||
Crypt::Digest::MD5::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/MD5|http://en.wikipedia.org/wiki/MD5>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/RIPEMD128.pm
Normal file
227
lib/Crypt/Digest/RIPEMD128.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::RIPEMD128;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ripemd128 ripemd128_hex ripemd128_b64 ripemd128_b64u ripemd128_file ripemd128_file_hex ripemd128_file_b64 ripemd128_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub ripemd128 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub ripemd128_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub ripemd128_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub ripemd128_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub ripemd128_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub ripemd128_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub ripemd128_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub ripemd128_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::RIPEMD128 - Hash function RIPEMD-128 [size: 128 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::RIPEMD128 qw( ripemd128 ripemd128_hex ripemd128_b64 ripemd128_b64u
|
||||
ripemd128_file ripemd128_file_hex ripemd128_file_b64 ripemd128_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$ripemd128_raw = ripemd128('data string');
|
||||
$ripemd128_hex = ripemd128_hex('data string');
|
||||
$ripemd128_b64 = ripemd128_b64('data string');
|
||||
$ripemd128_b64u = ripemd128_b64u('data string');
|
||||
# calculate digest from file
|
||||
$ripemd128_raw = ripemd128_file('filename.dat');
|
||||
$ripemd128_hex = ripemd128_file_hex('filename.dat');
|
||||
$ripemd128_b64 = ripemd128_file_b64('filename.dat');
|
||||
$ripemd128_b64u = ripemd128_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$ripemd128_raw = ripemd128_file(*FILEHANDLE);
|
||||
$ripemd128_hex = ripemd128_file_hex(*FILEHANDLE);
|
||||
$ripemd128_b64 = ripemd128_file_b64(*FILEHANDLE);
|
||||
$ripemd128_b64u = ripemd128_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::RIPEMD128;
|
||||
|
||||
$d = Crypt::Digest::RIPEMD128->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the RIPEMD128 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::RIPEMD128 qw(ripemd128 ripemd128_hex ripemd128_b64 ripemd128_b64u
|
||||
ripemd128_file ripemd128_file_hex ripemd128_file_b64 ripemd128_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::RIPEMD128 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ripemd128
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD128 digest encoded as a binary string.
|
||||
|
||||
$ripemd128_raw = ripemd128('data string');
|
||||
#or
|
||||
$ripemd128_raw = ripemd128('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd128_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD128 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd128_hex = ripemd128_hex('data string');
|
||||
#or
|
||||
$ripemd128_hex = ripemd128_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd128_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD128 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd128_b64 = ripemd128_b64('data string');
|
||||
#or
|
||||
$ripemd128_b64 = ripemd128_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd128_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD128 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd128_b64url = ripemd128_b64u('data string');
|
||||
#or
|
||||
$ripemd128_b64url = ripemd128_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd128_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD128 digest encoded as a binary string.
|
||||
|
||||
$ripemd128_raw = ripemd128_file('filename.dat');
|
||||
#or
|
||||
$ripemd128_raw = ripemd128_file(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd128_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD128 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd128_hex = ripemd128_file_hex('filename.dat');
|
||||
#or
|
||||
$ripemd128_hex = ripemd128_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 ripemd128_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD128 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd128_b64 = ripemd128_file_b64('filename.dat');
|
||||
#or
|
||||
$ripemd128_b64 = ripemd128_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd128_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD128 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd128_b64url = ripemd128_file_b64u('filename.dat');
|
||||
#or
|
||||
$ripemd128_b64url = ripemd128_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::RIPEMD128->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::RIPEMD128->hashsize();
|
||||
#or
|
||||
Crypt::Digest::RIPEMD128::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RIPEMD|http://en.wikipedia.org/wiki/RIPEMD>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/RIPEMD160.pm
Normal file
227
lib/Crypt/Digest/RIPEMD160.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::RIPEMD160;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ripemd160 ripemd160_hex ripemd160_b64 ripemd160_b64u ripemd160_file ripemd160_file_hex ripemd160_file_b64 ripemd160_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub ripemd160 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub ripemd160_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub ripemd160_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub ripemd160_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub ripemd160_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub ripemd160_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub ripemd160_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub ripemd160_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::RIPEMD160 - Hash function RIPEMD-160 [size: 160 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::RIPEMD160 qw( ripemd160 ripemd160_hex ripemd160_b64 ripemd160_b64u
|
||||
ripemd160_file ripemd160_file_hex ripemd160_file_b64 ripemd160_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$ripemd160_raw = ripemd160('data string');
|
||||
$ripemd160_hex = ripemd160_hex('data string');
|
||||
$ripemd160_b64 = ripemd160_b64('data string');
|
||||
$ripemd160_b64u = ripemd160_b64u('data string');
|
||||
# calculate digest from file
|
||||
$ripemd160_raw = ripemd160_file('filename.dat');
|
||||
$ripemd160_hex = ripemd160_file_hex('filename.dat');
|
||||
$ripemd160_b64 = ripemd160_file_b64('filename.dat');
|
||||
$ripemd160_b64u = ripemd160_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$ripemd160_raw = ripemd160_file(*FILEHANDLE);
|
||||
$ripemd160_hex = ripemd160_file_hex(*FILEHANDLE);
|
||||
$ripemd160_b64 = ripemd160_file_b64(*FILEHANDLE);
|
||||
$ripemd160_b64u = ripemd160_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::RIPEMD160;
|
||||
|
||||
$d = Crypt::Digest::RIPEMD160->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the RIPEMD160 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::RIPEMD160 qw(ripemd160 ripemd160_hex ripemd160_b64 ripemd160_b64u
|
||||
ripemd160_file ripemd160_file_hex ripemd160_file_b64 ripemd160_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::RIPEMD160 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ripemd160
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD160 digest encoded as a binary string.
|
||||
|
||||
$ripemd160_raw = ripemd160('data string');
|
||||
#or
|
||||
$ripemd160_raw = ripemd160('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd160_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD160 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd160_hex = ripemd160_hex('data string');
|
||||
#or
|
||||
$ripemd160_hex = ripemd160_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd160_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd160_b64 = ripemd160_b64('data string');
|
||||
#or
|
||||
$ripemd160_b64 = ripemd160_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd160_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd160_b64url = ripemd160_b64u('data string');
|
||||
#or
|
||||
$ripemd160_b64url = ripemd160_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd160_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD160 digest encoded as a binary string.
|
||||
|
||||
$ripemd160_raw = ripemd160_file('filename.dat');
|
||||
#or
|
||||
$ripemd160_raw = ripemd160_file(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd160_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD160 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd160_hex = ripemd160_file_hex('filename.dat');
|
||||
#or
|
||||
$ripemd160_hex = ripemd160_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 ripemd160_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD160 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd160_b64 = ripemd160_file_b64('filename.dat');
|
||||
#or
|
||||
$ripemd160_b64 = ripemd160_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd160_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD160 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd160_b64url = ripemd160_file_b64u('filename.dat');
|
||||
#or
|
||||
$ripemd160_b64url = ripemd160_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::RIPEMD160->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::RIPEMD160->hashsize();
|
||||
#or
|
||||
Crypt::Digest::RIPEMD160::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RIPEMD|http://en.wikipedia.org/wiki/RIPEMD>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/RIPEMD256.pm
Normal file
227
lib/Crypt/Digest/RIPEMD256.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::RIPEMD256;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ripemd256 ripemd256_hex ripemd256_b64 ripemd256_b64u ripemd256_file ripemd256_file_hex ripemd256_file_b64 ripemd256_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub ripemd256 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub ripemd256_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub ripemd256_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub ripemd256_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub ripemd256_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub ripemd256_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub ripemd256_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub ripemd256_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::RIPEMD256 - Hash function RIPEMD-256 [size: 256 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::RIPEMD256 qw( ripemd256 ripemd256_hex ripemd256_b64 ripemd256_b64u
|
||||
ripemd256_file ripemd256_file_hex ripemd256_file_b64 ripemd256_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$ripemd256_raw = ripemd256('data string');
|
||||
$ripemd256_hex = ripemd256_hex('data string');
|
||||
$ripemd256_b64 = ripemd256_b64('data string');
|
||||
$ripemd256_b64u = ripemd256_b64u('data string');
|
||||
# calculate digest from file
|
||||
$ripemd256_raw = ripemd256_file('filename.dat');
|
||||
$ripemd256_hex = ripemd256_file_hex('filename.dat');
|
||||
$ripemd256_b64 = ripemd256_file_b64('filename.dat');
|
||||
$ripemd256_b64u = ripemd256_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$ripemd256_raw = ripemd256_file(*FILEHANDLE);
|
||||
$ripemd256_hex = ripemd256_file_hex(*FILEHANDLE);
|
||||
$ripemd256_b64 = ripemd256_file_b64(*FILEHANDLE);
|
||||
$ripemd256_b64u = ripemd256_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::RIPEMD256;
|
||||
|
||||
$d = Crypt::Digest::RIPEMD256->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the RIPEMD256 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::RIPEMD256 qw(ripemd256 ripemd256_hex ripemd256_b64 ripemd256_b64u
|
||||
ripemd256_file ripemd256_file_hex ripemd256_file_b64 ripemd256_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::RIPEMD256 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ripemd256
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD256 digest encoded as a binary string.
|
||||
|
||||
$ripemd256_raw = ripemd256('data string');
|
||||
#or
|
||||
$ripemd256_raw = ripemd256('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd256_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD256 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd256_hex = ripemd256_hex('data string');
|
||||
#or
|
||||
$ripemd256_hex = ripemd256_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd256_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd256_b64 = ripemd256_b64('data string');
|
||||
#or
|
||||
$ripemd256_b64 = ripemd256_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd256_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd256_b64url = ripemd256_b64u('data string');
|
||||
#or
|
||||
$ripemd256_b64url = ripemd256_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd256_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD256 digest encoded as a binary string.
|
||||
|
||||
$ripemd256_raw = ripemd256_file('filename.dat');
|
||||
#or
|
||||
$ripemd256_raw = ripemd256_file(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd256_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD256 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd256_hex = ripemd256_file_hex('filename.dat');
|
||||
#or
|
||||
$ripemd256_hex = ripemd256_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 ripemd256_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd256_b64 = ripemd256_file_b64('filename.dat');
|
||||
#or
|
||||
$ripemd256_b64 = ripemd256_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd256_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd256_b64url = ripemd256_file_b64u('filename.dat');
|
||||
#or
|
||||
$ripemd256_b64url = ripemd256_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::RIPEMD256->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::RIPEMD256->hashsize();
|
||||
#or
|
||||
Crypt::Digest::RIPEMD256::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RIPEMD|http://en.wikipedia.org/wiki/RIPEMD>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/RIPEMD320.pm
Normal file
227
lib/Crypt/Digest/RIPEMD320.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::RIPEMD320;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( ripemd320 ripemd320_hex ripemd320_b64 ripemd320_b64u ripemd320_file ripemd320_file_hex ripemd320_file_b64 ripemd320_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub ripemd320 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub ripemd320_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub ripemd320_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub ripemd320_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub ripemd320_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub ripemd320_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub ripemd320_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub ripemd320_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::RIPEMD320 - Hash function RIPEMD-320 [size: 320 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::RIPEMD320 qw( ripemd320 ripemd320_hex ripemd320_b64 ripemd320_b64u
|
||||
ripemd320_file ripemd320_file_hex ripemd320_file_b64 ripemd320_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$ripemd320_raw = ripemd320('data string');
|
||||
$ripemd320_hex = ripemd320_hex('data string');
|
||||
$ripemd320_b64 = ripemd320_b64('data string');
|
||||
$ripemd320_b64u = ripemd320_b64u('data string');
|
||||
# calculate digest from file
|
||||
$ripemd320_raw = ripemd320_file('filename.dat');
|
||||
$ripemd320_hex = ripemd320_file_hex('filename.dat');
|
||||
$ripemd320_b64 = ripemd320_file_b64('filename.dat');
|
||||
$ripemd320_b64u = ripemd320_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$ripemd320_raw = ripemd320_file(*FILEHANDLE);
|
||||
$ripemd320_hex = ripemd320_file_hex(*FILEHANDLE);
|
||||
$ripemd320_b64 = ripemd320_file_b64(*FILEHANDLE);
|
||||
$ripemd320_b64u = ripemd320_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::RIPEMD320;
|
||||
|
||||
$d = Crypt::Digest::RIPEMD320->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the RIPEMD320 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::RIPEMD320 qw(ripemd320 ripemd320_hex ripemd320_b64 ripemd320_b64u
|
||||
ripemd320_file ripemd320_file_hex ripemd320_file_b64 ripemd320_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::RIPEMD320 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 ripemd320
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD320 digest encoded as a binary string.
|
||||
|
||||
$ripemd320_raw = ripemd320('data string');
|
||||
#or
|
||||
$ripemd320_raw = ripemd320('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd320_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD320 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd320_hex = ripemd320_hex('data string');
|
||||
#or
|
||||
$ripemd320_hex = ripemd320_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd320_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD320 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd320_b64 = ripemd320_b64('data string');
|
||||
#or
|
||||
$ripemd320_b64 = ripemd320_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd320_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its RIPEMD320 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd320_b64url = ripemd320_b64u('data string');
|
||||
#or
|
||||
$ripemd320_b64url = ripemd320_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 ripemd320_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD320 digest encoded as a binary string.
|
||||
|
||||
$ripemd320_raw = ripemd320_file('filename.dat');
|
||||
#or
|
||||
$ripemd320_raw = ripemd320_file(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd320_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD320 digest encoded as a hexadecimal string.
|
||||
|
||||
$ripemd320_hex = ripemd320_file_hex('filename.dat');
|
||||
#or
|
||||
$ripemd320_hex = ripemd320_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 ripemd320_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD320 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$ripemd320_b64 = ripemd320_file_b64('filename.dat');
|
||||
#or
|
||||
$ripemd320_b64 = ripemd320_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 ripemd320_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its RIPEMD320 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$ripemd320_b64url = ripemd320_file_b64u('filename.dat');
|
||||
#or
|
||||
$ripemd320_b64url = ripemd320_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::RIPEMD320->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::RIPEMD320->hashsize();
|
||||
#or
|
||||
Crypt::Digest::RIPEMD320::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/RIPEMD|http://en.wikipedia.org/wiki/RIPEMD>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA1.pm
Normal file
227
lib/Crypt/Digest/SHA1.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA1;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( sha1 sha1_hex sha1_b64 sha1_b64u sha1_file sha1_file_hex sha1_file_b64 sha1_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha1 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha1_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha1_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha1_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha1_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha1_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha1_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha1_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA1 - Hash function SHA-1 [size: 160 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA1 qw( sha1 sha1_hex sha1_b64 sha1_b64u
|
||||
sha1_file sha1_file_hex sha1_file_b64 sha1_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha1_raw = sha1('data string');
|
||||
$sha1_hex = sha1_hex('data string');
|
||||
$sha1_b64 = sha1_b64('data string');
|
||||
$sha1_b64u = sha1_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha1_raw = sha1_file('filename.dat');
|
||||
$sha1_hex = sha1_file_hex('filename.dat');
|
||||
$sha1_b64 = sha1_file_b64('filename.dat');
|
||||
$sha1_b64u = sha1_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha1_raw = sha1_file(*FILEHANDLE);
|
||||
$sha1_hex = sha1_file_hex(*FILEHANDLE);
|
||||
$sha1_b64 = sha1_file_b64(*FILEHANDLE);
|
||||
$sha1_b64u = sha1_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA1;
|
||||
|
||||
$d = Crypt::Digest::SHA1->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA1 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA1 qw(sha1 sha1_hex sha1_b64 sha1_b64u
|
||||
sha1_file sha1_file_hex sha1_file_b64 sha1_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA1 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha1
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a binary string.
|
||||
|
||||
$sha1_raw = sha1('data string');
|
||||
#or
|
||||
$sha1_raw = sha1('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha1_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha1_hex = sha1_hex('data string');
|
||||
#or
|
||||
$sha1_hex = sha1_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha1_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha1_b64 = sha1_b64('data string');
|
||||
#or
|
||||
$sha1_b64 = sha1_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha1_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA1 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha1_b64url = sha1_b64u('data string');
|
||||
#or
|
||||
$sha1_b64url = sha1_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha1_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA1 digest encoded as a binary string.
|
||||
|
||||
$sha1_raw = sha1_file('filename.dat');
|
||||
#or
|
||||
$sha1_raw = sha1_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha1_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA1 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha1_hex = sha1_file_hex('filename.dat');
|
||||
#or
|
||||
$sha1_hex = sha1_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha1_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA1 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha1_b64 = sha1_file_b64('filename.dat');
|
||||
#or
|
||||
$sha1_b64 = sha1_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha1_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA1 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha1_b64url = sha1_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha1_b64url = sha1_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA1->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA1->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA1::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-1|http://en.wikipedia.org/wiki/SHA-1>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA224.pm
Normal file
227
lib/Crypt/Digest/SHA224.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA224;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( sha224 sha224_hex sha224_b64 sha224_b64u sha224_file sha224_file_hex sha224_file_b64 sha224_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha224 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha224_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha224_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha224_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha224_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha224_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha224_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha224_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA224 - Hash function SHA-224 [size: 224 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA224 qw( sha224 sha224_hex sha224_b64 sha224_b64u
|
||||
sha224_file sha224_file_hex sha224_file_b64 sha224_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha224_raw = sha224('data string');
|
||||
$sha224_hex = sha224_hex('data string');
|
||||
$sha224_b64 = sha224_b64('data string');
|
||||
$sha224_b64u = sha224_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha224_raw = sha224_file('filename.dat');
|
||||
$sha224_hex = sha224_file_hex('filename.dat');
|
||||
$sha224_b64 = sha224_file_b64('filename.dat');
|
||||
$sha224_b64u = sha224_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha224_raw = sha224_file(*FILEHANDLE);
|
||||
$sha224_hex = sha224_file_hex(*FILEHANDLE);
|
||||
$sha224_b64 = sha224_file_b64(*FILEHANDLE);
|
||||
$sha224_b64u = sha224_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA224;
|
||||
|
||||
$d = Crypt::Digest::SHA224->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA224 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA224 qw(sha224 sha224_hex sha224_b64 sha224_b64u
|
||||
sha224_file sha224_file_hex sha224_file_b64 sha224_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA224 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha224
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA224 digest encoded as a binary string.
|
||||
|
||||
$sha224_raw = sha224('data string');
|
||||
#or
|
||||
$sha224_raw = sha224('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha224_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA224 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha224_hex = sha224_hex('data string');
|
||||
#or
|
||||
$sha224_hex = sha224_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha224_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha224_b64 = sha224_b64('data string');
|
||||
#or
|
||||
$sha224_b64 = sha224_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha224_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha224_b64url = sha224_b64u('data string');
|
||||
#or
|
||||
$sha224_b64url = sha224_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha224_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA224 digest encoded as a binary string.
|
||||
|
||||
$sha224_raw = sha224_file('filename.dat');
|
||||
#or
|
||||
$sha224_raw = sha224_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha224_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA224 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha224_hex = sha224_file_hex('filename.dat');
|
||||
#or
|
||||
$sha224_hex = sha224_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha224_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha224_b64 = sha224_file_b64('filename.dat');
|
||||
#or
|
||||
$sha224_b64 = sha224_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha224_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha224_b64url = sha224_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha224_b64url = sha224_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA224->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA224->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA224::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-2|http://en.wikipedia.org/wiki/SHA-2>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA256.pm
Normal file
227
lib/Crypt/Digest/SHA256.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA256;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( sha256 sha256_hex sha256_b64 sha256_b64u sha256_file sha256_file_hex sha256_file_b64 sha256_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha256 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha256_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha256_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha256_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha256_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha256_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha256_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha256_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA256 - Hash function SHA-256 [size: 256 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA256 qw( sha256 sha256_hex sha256_b64 sha256_b64u
|
||||
sha256_file sha256_file_hex sha256_file_b64 sha256_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha256_raw = sha256('data string');
|
||||
$sha256_hex = sha256_hex('data string');
|
||||
$sha256_b64 = sha256_b64('data string');
|
||||
$sha256_b64u = sha256_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha256_raw = sha256_file('filename.dat');
|
||||
$sha256_hex = sha256_file_hex('filename.dat');
|
||||
$sha256_b64 = sha256_file_b64('filename.dat');
|
||||
$sha256_b64u = sha256_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha256_raw = sha256_file(*FILEHANDLE);
|
||||
$sha256_hex = sha256_file_hex(*FILEHANDLE);
|
||||
$sha256_b64 = sha256_file_b64(*FILEHANDLE);
|
||||
$sha256_b64u = sha256_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA256;
|
||||
|
||||
$d = Crypt::Digest::SHA256->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA256 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA256 qw(sha256 sha256_hex sha256_b64 sha256_b64u
|
||||
sha256_file sha256_file_hex sha256_file_b64 sha256_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA256 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha256
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA256 digest encoded as a binary string.
|
||||
|
||||
$sha256_raw = sha256('data string');
|
||||
#or
|
||||
$sha256_raw = sha256('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha256_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA256 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha256_hex = sha256_hex('data string');
|
||||
#or
|
||||
$sha256_hex = sha256_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha256_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha256_b64 = sha256_b64('data string');
|
||||
#or
|
||||
$sha256_b64 = sha256_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha256_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha256_b64url = sha256_b64u('data string');
|
||||
#or
|
||||
$sha256_b64url = sha256_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha256_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA256 digest encoded as a binary string.
|
||||
|
||||
$sha256_raw = sha256_file('filename.dat');
|
||||
#or
|
||||
$sha256_raw = sha256_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha256_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA256 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha256_hex = sha256_file_hex('filename.dat');
|
||||
#or
|
||||
$sha256_hex = sha256_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha256_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha256_b64 = sha256_file_b64('filename.dat');
|
||||
#or
|
||||
$sha256_b64 = sha256_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha256_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha256_b64url = sha256_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha256_b64url = sha256_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA256->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA256->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA256::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-2|http://en.wikipedia.org/wiki/SHA-2>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA384.pm
Normal file
227
lib/Crypt/Digest/SHA384.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA384;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
our %EXPORT_TAGS = ( all => [qw( sha384 sha384_hex sha384_b64 sha384_b64u sha384_file sha384_file_hex sha384_file_b64 sha384_file_b64u )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha384 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha384_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha384_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha384_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha384_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha384_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha384_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha384_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA384 - Hash function SHA-384 [size: 384 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA384 qw( sha384 sha384_hex sha384_b64 sha384_b64u
|
||||
sha384_file sha384_file_hex sha384_file_b64 sha384_file_b64u );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha384_raw = sha384('data string');
|
||||
$sha384_hex = sha384_hex('data string');
|
||||
$sha384_b64 = sha384_b64('data string');
|
||||
$sha384_b64u = sha384_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha384_raw = sha384_file('filename.dat');
|
||||
$sha384_hex = sha384_file_hex('filename.dat');
|
||||
$sha384_b64 = sha384_file_b64('filename.dat');
|
||||
$sha384_b64u = sha384_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha384_raw = sha384_file(*FILEHANDLE);
|
||||
$sha384_hex = sha384_file_hex(*FILEHANDLE);
|
||||
$sha384_b64 = sha384_file_b64(*FILEHANDLE);
|
||||
$sha384_b64u = sha384_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA384;
|
||||
|
||||
$d = Crypt::Digest::SHA384->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA384 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA384 qw(sha384 sha384_hex sha384_b64 sha384_b64u
|
||||
sha384_file sha384_file_hex sha384_file_b64 sha384_file_b64u);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA384 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha384
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA384 digest encoded as a binary string.
|
||||
|
||||
$sha384_raw = sha384('data string');
|
||||
#or
|
||||
$sha384_raw = sha384('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha384_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA384 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha384_hex = sha384_hex('data string');
|
||||
#or
|
||||
$sha384_hex = sha384_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha384_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha384_b64 = sha384_b64('data string');
|
||||
#or
|
||||
$sha384_b64 = sha384_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha384_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha384_b64url = sha384_b64u('data string');
|
||||
#or
|
||||
$sha384_b64url = sha384_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha384_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA384 digest encoded as a binary string.
|
||||
|
||||
$sha384_raw = sha384_file('filename.dat');
|
||||
#or
|
||||
$sha384_raw = sha384_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha384_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA384 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha384_hex = sha384_file_hex('filename.dat');
|
||||
#or
|
||||
$sha384_hex = sha384_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha384_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha384_b64 = sha384_file_b64('filename.dat');
|
||||
#or
|
||||
$sha384_b64 = sha384_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha384_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha384_b64url = sha384_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha384_b64url = sha384_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA384->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA384->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA384::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-2|http://en.wikipedia.org/wiki/SHA-2>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA3_224.pm
Normal file
227
lib/Crypt/Digest/SHA3_224.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA3_224;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha3_224 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha3_224_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha3_224_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha3_224_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha3_224_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha3_224_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha3_224_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha3_224_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA3_224 - Hash function SHA3-224 [size: 224 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA3_224 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha3_224_raw = sha3_224('data string');
|
||||
$sha3_224_hex = sha3_224_hex('data string');
|
||||
$sha3_224_b64 = sha3_224_b64('data string');
|
||||
$sha3_224_b64u = sha3_224_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha3_224_raw = sha3_224_file('filename.dat');
|
||||
$sha3_224_hex = sha3_224_file_hex('filename.dat');
|
||||
$sha3_224_b64 = sha3_224_file_b64('filename.dat');
|
||||
$sha3_224_b64u = sha3_224_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha3_224_raw = sha3_224_file(*FILEHANDLE);
|
||||
$sha3_224_hex = sha3_224_file_hex(*FILEHANDLE);
|
||||
$sha3_224_b64 = sha3_224_file_b64(*FILEHANDLE);
|
||||
$sha3_224_b64u = sha3_224_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA3_224;
|
||||
|
||||
$d = Crypt::Digest::SHA3_224->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA3_224 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA3_224 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA3_224 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha3_224
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_224 digest encoded as a binary string.
|
||||
|
||||
$sha3_224_raw = sha3_224('data string');
|
||||
#or
|
||||
$sha3_224_raw = sha3_224('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_224_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_224 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_224_hex = sha3_224_hex('data string');
|
||||
#or
|
||||
$sha3_224_hex = sha3_224_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_224_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_224_b64 = sha3_224_b64('data string');
|
||||
#or
|
||||
$sha3_224_b64 = sha3_224_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_224_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_224_b64url = sha3_224_b64u('data string');
|
||||
#or
|
||||
$sha3_224_b64url = sha3_224_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_224_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_224 digest encoded as a binary string.
|
||||
|
||||
$sha3_224_raw = sha3_224_file('filename.dat');
|
||||
#or
|
||||
$sha3_224_raw = sha3_224_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_224_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_224 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_224_hex = sha3_224_file_hex('filename.dat');
|
||||
#or
|
||||
$sha3_224_hex = sha3_224_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha3_224_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_224 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_224_b64 = sha3_224_file_b64('filename.dat');
|
||||
#or
|
||||
$sha3_224_b64 = sha3_224_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_224_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_224 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_224_b64url = sha3_224_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha3_224_b64url = sha3_224_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA3_224->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA3_224->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA3_224::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-3|http://en.wikipedia.org/wiki/SHA-3>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA3_256.pm
Normal file
227
lib/Crypt/Digest/SHA3_256.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA3_256;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha3_256 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha3_256_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha3_256_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha3_256_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha3_256_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha3_256_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha3_256_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha3_256_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA3_256 - Hash function SHA3-256 [size: 256 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA3_256 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha3_256_raw = sha3_256('data string');
|
||||
$sha3_256_hex = sha3_256_hex('data string');
|
||||
$sha3_256_b64 = sha3_256_b64('data string');
|
||||
$sha3_256_b64u = sha3_256_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha3_256_raw = sha3_256_file('filename.dat');
|
||||
$sha3_256_hex = sha3_256_file_hex('filename.dat');
|
||||
$sha3_256_b64 = sha3_256_file_b64('filename.dat');
|
||||
$sha3_256_b64u = sha3_256_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha3_256_raw = sha3_256_file(*FILEHANDLE);
|
||||
$sha3_256_hex = sha3_256_file_hex(*FILEHANDLE);
|
||||
$sha3_256_b64 = sha3_256_file_b64(*FILEHANDLE);
|
||||
$sha3_256_b64u = sha3_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA3_256;
|
||||
|
||||
$d = Crypt::Digest::SHA3_256->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA3_256 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA3_256 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA3_256 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha3_256
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_256 digest encoded as a binary string.
|
||||
|
||||
$sha3_256_raw = sha3_256('data string');
|
||||
#or
|
||||
$sha3_256_raw = sha3_256('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_256_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_256_hex = sha3_256_hex('data string');
|
||||
#or
|
||||
$sha3_256_hex = sha3_256_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_256_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_256_b64 = sha3_256_b64('data string');
|
||||
#or
|
||||
$sha3_256_b64 = sha3_256_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_256_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_256_b64url = sha3_256_b64u('data string');
|
||||
#or
|
||||
$sha3_256_b64url = sha3_256_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_256_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_256 digest encoded as a binary string.
|
||||
|
||||
$sha3_256_raw = sha3_256_file('filename.dat');
|
||||
#or
|
||||
$sha3_256_raw = sha3_256_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_256_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_256 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_256_hex = sha3_256_file_hex('filename.dat');
|
||||
#or
|
||||
$sha3_256_hex = sha3_256_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha3_256_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_256 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_256_b64 = sha3_256_file_b64('filename.dat');
|
||||
#or
|
||||
$sha3_256_b64 = sha3_256_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_256_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_256 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_256_b64url = sha3_256_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha3_256_b64url = sha3_256_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA3_256->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA3_256->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA3_256::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-3|http://en.wikipedia.org/wiki/SHA-3>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA3_384.pm
Normal file
227
lib/Crypt/Digest/SHA3_384.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA3_384;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha3_384 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha3_384_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha3_384_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha3_384_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha3_384_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha3_384_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha3_384_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha3_384_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA3_384 - Hash function SHA3-384 [size: 384 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA3_384 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha3_384_raw = sha3_384('data string');
|
||||
$sha3_384_hex = sha3_384_hex('data string');
|
||||
$sha3_384_b64 = sha3_384_b64('data string');
|
||||
$sha3_384_b64u = sha3_384_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha3_384_raw = sha3_384_file('filename.dat');
|
||||
$sha3_384_hex = sha3_384_file_hex('filename.dat');
|
||||
$sha3_384_b64 = sha3_384_file_b64('filename.dat');
|
||||
$sha3_384_b64u = sha3_384_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha3_384_raw = sha3_384_file(*FILEHANDLE);
|
||||
$sha3_384_hex = sha3_384_file_hex(*FILEHANDLE);
|
||||
$sha3_384_b64 = sha3_384_file_b64(*FILEHANDLE);
|
||||
$sha3_384_b64u = sha3_384_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA3_384;
|
||||
|
||||
$d = Crypt::Digest::SHA3_384->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA3_384 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA3_384 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA3_384 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha3_384
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_384 digest encoded as a binary string.
|
||||
|
||||
$sha3_384_raw = sha3_384('data string');
|
||||
#or
|
||||
$sha3_384_raw = sha3_384('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_384_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_384 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_384_hex = sha3_384_hex('data string');
|
||||
#or
|
||||
$sha3_384_hex = sha3_384_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_384_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_384_b64 = sha3_384_b64('data string');
|
||||
#or
|
||||
$sha3_384_b64 = sha3_384_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_384_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_384_b64url = sha3_384_b64u('data string');
|
||||
#or
|
||||
$sha3_384_b64url = sha3_384_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_384_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_384 digest encoded as a binary string.
|
||||
|
||||
$sha3_384_raw = sha3_384_file('filename.dat');
|
||||
#or
|
||||
$sha3_384_raw = sha3_384_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_384_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_384 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_384_hex = sha3_384_file_hex('filename.dat');
|
||||
#or
|
||||
$sha3_384_hex = sha3_384_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha3_384_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_384 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_384_b64 = sha3_384_file_b64('filename.dat');
|
||||
#or
|
||||
$sha3_384_b64 = sha3_384_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_384_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_384 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_384_b64url = sha3_384_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha3_384_b64url = sha3_384_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA3_384->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA3_384->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA3_384::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-3|http://en.wikipedia.org/wiki/SHA-3>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
227
lib/Crypt/Digest/SHA3_512.pm
Normal file
227
lib/Crypt/Digest/SHA3_512.pm
Normal file
@ -0,0 +1,227 @@
|
||||
package Crypt::Digest::SHA3_512;
|
||||
|
||||
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our $VERSION = '0.048';
|
||||
|
||||
use base qw(Crypt::Digest Exporter);
|
||||
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 )] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
|
||||
use Carp;
|
||||
$Carp::Internal{(__PACKAGE__)}++;
|
||||
use CryptX;
|
||||
|
||||
sub hashsize { Crypt::Digest::hashsize(__PACKAGE__) }
|
||||
|
||||
sub sha3_512 { Crypt::Digest::digest_data(__PACKAGE__, @_) }
|
||||
sub sha3_512_hex { Crypt::Digest::digest_data_hex(__PACKAGE__, @_) }
|
||||
sub sha3_512_b64 { Crypt::Digest::digest_data_b64(__PACKAGE__, @_) }
|
||||
sub sha3_512_b64u { Crypt::Digest::digest_data_b64u(__PACKAGE__, @_) }
|
||||
|
||||
sub sha3_512_file { Crypt::Digest::digest_file(__PACKAGE__, @_) }
|
||||
sub sha3_512_file_hex { Crypt::Digest::digest_file_hex(__PACKAGE__, @_) }
|
||||
sub sha3_512_file_b64 { Crypt::Digest::digest_file_b64(__PACKAGE__, @_) }
|
||||
sub sha3_512_file_b64u { Crypt::Digest::digest_file_b64u(__PACKAGE__, @_) }
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Crypt::Digest::SHA3_512 - Hash function SHA3-512 [size: 512 bits]
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
### Functional interface:
|
||||
use Crypt::Digest::SHA3_512 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 );
|
||||
|
||||
# calculate digest from string/buffer
|
||||
$sha3_512_raw = sha3_512('data string');
|
||||
$sha3_512_hex = sha3_512_hex('data string');
|
||||
$sha3_512_b64 = sha3_512_b64('data string');
|
||||
$sha3_512_b64u = sha3_512_b64u('data string');
|
||||
# calculate digest from file
|
||||
$sha3_512_raw = sha3_512_file('filename.dat');
|
||||
$sha3_512_hex = sha3_512_file_hex('filename.dat');
|
||||
$sha3_512_b64 = sha3_512_file_b64('filename.dat');
|
||||
$sha3_512_b64u = sha3_512_file_b64u('filename.dat');
|
||||
# calculate digest from filehandle
|
||||
$sha3_512_raw = sha3_512_file(*FILEHANDLE);
|
||||
$sha3_512_hex = sha3_512_file_hex(*FILEHANDLE);
|
||||
$sha3_512_b64 = sha3_512_file_b64(*FILEHANDLE);
|
||||
$sha3_512_b64u = sha3_512_file_b64u(*FILEHANDLE);
|
||||
|
||||
### OO interface:
|
||||
use Crypt::Digest::SHA3_512;
|
||||
|
||||
$d = Crypt::Digest::SHA3_512->new;
|
||||
$d->add('any data');
|
||||
$d->addfile('filename.dat');
|
||||
$d->addfile(*FILEHANDLE);
|
||||
$result_raw = $d->digest; # raw bytes
|
||||
$result_hex = $d->hexdigest; # hexadecimal form
|
||||
$result_b64 = $d->b64digest; # Base64 form
|
||||
$result_b64u = $d->b64udigest; # Base64 URL Safe form
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides an interface to the SHA3_512 digest algorithm.
|
||||
|
||||
=head1 EXPORT
|
||||
|
||||
Nothing is exported by default.
|
||||
|
||||
You can export selected functions:
|
||||
|
||||
use Crypt::Digest::SHA3_512 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);
|
||||
|
||||
Or all of them at once:
|
||||
|
||||
use Crypt::Digest::SHA3_512 ':all';
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
=head2 sha3_512
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_512 digest encoded as a binary string.
|
||||
|
||||
$sha3_512_raw = sha3_512('data string');
|
||||
#or
|
||||
$sha3_512_raw = sha3_512('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_512_hex
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_512 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_512_hex = sha3_512_hex('data string');
|
||||
#or
|
||||
$sha3_512_hex = sha3_512_hex('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_512_b64
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_512 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_512_b64 = sha3_512_b64('data string');
|
||||
#or
|
||||
$sha3_512_b64 = sha3_512_b64('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_512_b64u
|
||||
|
||||
Logically joins all arguments into a single string, and returns its SHA3_512 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_512_b64url = sha3_512_b64u('data string');
|
||||
#or
|
||||
$sha3_512_b64url = sha3_512_b64u('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 sha3_512_file
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_512 digest encoded as a binary string.
|
||||
|
||||
$sha3_512_raw = sha3_512_file('filename.dat');
|
||||
#or
|
||||
$sha3_512_raw = sha3_512_file(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_512_file_hex
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_512 digest encoded as a hexadecimal string.
|
||||
|
||||
$sha3_512_hex = sha3_512_file_hex('filename.dat');
|
||||
#or
|
||||
$sha3_512_hex = sha3_512_file_hex(*FILEHANDLE);
|
||||
|
||||
B<BEWARE:> You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method.
|
||||
|
||||
=head2 sha3_512_file_b64
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_512 digest encoded as a Base64 string, B<with> trailing '=' padding.
|
||||
|
||||
$sha3_512_b64 = sha3_512_file_b64('filename.dat');
|
||||
#or
|
||||
$sha3_512_b64 = sha3_512_file_b64(*FILEHANDLE);
|
||||
|
||||
=head2 sha3_512_file_b64u
|
||||
|
||||
Reads file (defined by filename or filehandle) content, and returns its SHA3_512 digest encoded as a Base64 URL Safe string (see RFC 4648 section 5).
|
||||
|
||||
$sha3_512_b64url = sha3_512_file_b64u('filename.dat');
|
||||
#or
|
||||
$sha3_512_b64url = sha3_512_file_b64u(*FILEHANDLE);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The OO interface provides the same set of functions as L<Crypt::Digest>.
|
||||
|
||||
=head2 new
|
||||
|
||||
$d = Crypt::Digest::SHA3_512->new();
|
||||
|
||||
=head2 clone
|
||||
|
||||
$d->clone();
|
||||
|
||||
=head2 reset
|
||||
|
||||
$d->reset();
|
||||
|
||||
=head2 add
|
||||
|
||||
$d->add('any data');
|
||||
#or
|
||||
$d->add('any data', 'more data', 'even more data');
|
||||
|
||||
=head2 addfile
|
||||
|
||||
$d->addfile('filename.dat');
|
||||
#or
|
||||
$d->addfile(*FILEHANDLE);
|
||||
|
||||
=head2 add_bits
|
||||
|
||||
$d->add_bits($bit_string); # e.g. $d->add_bits("111100001010");
|
||||
#or
|
||||
$d->add_bits($data, $nbits); # e.g. $d->add_bits("\xF0\xA0", 16);
|
||||
|
||||
=head2 hashsize
|
||||
|
||||
$d->hashsize;
|
||||
#or
|
||||
Crypt::Digest::SHA3_512->hashsize();
|
||||
#or
|
||||
Crypt::Digest::SHA3_512::hashsize();
|
||||
|
||||
=head2 digest
|
||||
|
||||
$result_raw = $d->digest();
|
||||
|
||||
=head2 hexdigest
|
||||
|
||||
$result_hex = $d->hexdigest();
|
||||
|
||||
=head2 b64digest
|
||||
|
||||
$result_b64 = $d->b64digest();
|
||||
|
||||
=head2 b64udigest
|
||||
|
||||
$result_b64url = $d->b64udigest();
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
=over
|
||||
|
||||
=item * L<CryptX|CryptX>, L<Crypt::Digest|Crypt::Digest>
|
||||
|
||||
=item * L<http://en.wikipedia.org/wiki/SHA-3|http://en.wikipedia.org/wiki/SHA-3>
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
__END__
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user