CryptX
view release on metacpan or search on metacpan
src/ltc/headers/tomcrypt_private.h view on Meta::CPAN
enum ltc_oid_id {
LTC_OID_UNDEF,
LTC_OID_RSA,
LTC_OID_DSA,
LTC_OID_EC,
LTC_OID_EC_PRIMEF,
LTC_OID_X25519,
LTC_OID_ED25519,
LTC_OID_X448,
LTC_OID_ED448,
LTC_OID_DH,
LTC_OID_RSA_OAEP,
LTC_OID_RSA_MGF1,
LTC_OID_RSA_PSS,
LTC_OID_NUM
};
/*
* Internal Types
*/
typedef struct {
int size;
const char *name, *base, *prime;
} ltc_dh_set_type;
struct password {
/* usually a `char*` but could also contain binary data
* so use a `void*` + length to be on the safe side.
*/
void *pw;
unsigned long l;
};
typedef int (*fn_kdf_t)(const struct password *pwd,
const unsigned char *salt, unsigned long salt_len,
int iteration_count, int hash_idx,
unsigned char *out, unsigned long *outlen);
#if defined(LTC_PBES)
typedef struct {
/* KDF */
fn_kdf_t kdf;
/* Hash or HMAC */
const char* h;
/* cipher */
const char* c;
unsigned long keylen;
/* not used for pbkdf2 */
unsigned long blocklen;
} pbes_properties;
typedef struct
{
pbes_properties type;
struct password pw;
ltc_asn1_list *enc_data;
ltc_asn1_list *salt;
ltc_asn1_list *iv;
unsigned long iterations;
/* only used for RC2 */
unsigned long key_bits;
} pbes_arg;
typedef struct {
const pbes_properties *data;
const char *oid;
} oid_to_pbes;
#endif
/*
* Internal functions
*/
/* tomcrypt_cipher.h */
int ecb_encrypt_block(const unsigned char *pt, unsigned char *ct, const symmetric_ECB *ecb);
int ecb_decrypt_block(const unsigned char *ct, unsigned char *pt, const symmetric_ECB *ecb);
void blowfish_enc(ulong32 *data, unsigned long blocks, const symmetric_key *skey);
int blowfish_expand(const unsigned char *key, int keylen,
const unsigned char *data, int datalen,
symmetric_key *skey);
int blowfish_setup_with_data(const unsigned char *key, int keylen,
const unsigned char *data, int datalen,
symmetric_key *skey);
/* tomcrypt_hash.h */
/* a simple macro for making hash "process" functions */
#define HASH_PROCESS(func_name, compress_name, state_var, block_size) \
int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \
{ \
unsigned long n; \
int err; \
LTC_ARGCHK(md != NULL); \
LTC_ARGCHK(in != NULL); \
if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \
return CRYPT_INVALID_ARG; \
} \
if (((md-> state_var .length + inlen * 8) < md-> state_var .length) \
|| ((inlen * 8) < inlen)) { \
return CRYPT_HASH_OVERFLOW; \
} \
while (inlen > 0) { \
if (md-> state_var .curlen == 0 && inlen >= block_size) { \
if ((err = compress_name (md, in)) != CRYPT_OK) { \
return err; \
} \
md-> state_var .length += block_size * 8; \
in += block_size; \
inlen -= block_size; \
} else { \
n = MIN(inlen, (block_size - md-> state_var .curlen)); \
XMEMCPY(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \
md-> state_var .curlen += n; \
in += n; \
inlen -= n; \
src/ltc/headers/tomcrypt_private.h view on Meta::CPAN
int ltc_pkcs_1_v1_5_encode(const unsigned char *msg,
unsigned long msglen,
int block_type,
unsigned long modulus_bitlen,
prng_state *prng,
int prng_idx,
unsigned char *out,
unsigned long *outlen);
int ltc_pkcs_1_v1_5_decode(const unsigned char *msg,
unsigned long msglen,
int block_type,
unsigned long modulus_bitlen,
unsigned char *out,
unsigned long *outlen,
int *is_valid);
#endif /* LTC_PKCS_1 */
#ifdef LTC_PKCS_8
/* Public-Key Cryptography Standards (PKCS) #8:
* Private-Key Information Syntax Specification Version 1.2
* https://tools.ietf.org/html/rfc5208
*
* PrivateKeyInfo ::= SEQUENCE {
* version Version,
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
* privateKey PrivateKey,
* attributes [0] IMPLICIT Attributes OPTIONAL }
* where:
* - Version ::= INTEGER
* - PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
* - PrivateKey ::= OCTET STRING
* - Attributes ::= SET OF Attribute
*
* EncryptedPrivateKeyInfo ::= SEQUENCE {
* encryptionAlgorithm EncryptionAlgorithmIdentifier,
* encryptedData EncryptedData }
* where:
* - EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
* - EncryptedData ::= OCTET STRING
*/
int pkcs8_decode_flexi(const unsigned char *in, unsigned long inlen,
const password_ctx *pw_ctx,
ltc_asn1_list **decoded_list);
int pkcs8_get_children(const ltc_asn1_list *decoded_list, enum ltc_oid_id *pka,
ltc_asn1_list **alg_id, ltc_asn1_list **priv_key);
#endif /* LTC_PKCS_8 */
#ifdef LTC_PKCS_12
int pkcs12_utf8_to_utf16(const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
int pkcs12_kdf( int hash_id,
const unsigned char *pw, unsigned long pwlen,
const unsigned char *salt, unsigned long saltlen,
unsigned int iterations, unsigned char purpose,
unsigned char *out, unsigned long outlen);
#endif /* LTC_PKCS_12 */
/* tomcrypt_prng.h */
#define LTC_PRNG_EXPORT(which) \
int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng) \
{ \
unsigned long len = which ## _desc.export_size; \
\
LTC_ARGCHK(prng != NULL); \
LTC_ARGCHK(out != NULL); \
LTC_ARGCHK(outlen != NULL); \
\
if (*outlen < len) { \
*outlen = len; \
return CRYPT_BUFFER_OVERFLOW; \
} \
\
if (which ## _read(out, len, prng) != len) { \
return CRYPT_ERROR_READPRNG; \
} \
\
*outlen = len; \
return CRYPT_OK; \
}
/* extract a byte portably */
#ifdef _MSC_VER
#define LTC_BYTE(x, n) ((unsigned char)((x) >> (8 * (n))))
#else
#define LTC_BYTE(x, n) (((x) >> (8 * (n))) & 255)
#endif
/*
* On Windows, choose whether to use CryptGenRandom() [older Windows versions]
* or BCryptGenRandom() [newer Windows versions].
* If CryptGenRandom() is desired, define LTC_NO_WIN32_BCRYPT when building.
*/
#if defined(_MSC_VER) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
#if !defined(LTC_NO_WIN32_BCRYPT)
#define LTC_WIN32_BCRYPT
#endif
#endif
#endif /* TOMCRYPT_PRIVATE_H_ */
( run in 1.561 second using v1.01-cache-2.11-cpan-71847e10f99 )