1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */ 2 /* SPDX-License-Identifier: Unlicense */ 3 4 /* PKCS Header Info */ 5 6 /* ===> PKCS #1 -- RSA Cryptography <=== */ 7 #ifdef LTC_PKCS_1 8 9 enum ltc_pkcs_1_v1_5_blocks 10 { 11 LTC_PKCS_1_EMSA = 1, /* Block type 1 (PKCS #1 v1.5 signature padding) */ 12 LTC_PKCS_1_EME = 2 /* Block type 2 (PKCS #1 v1.5 encryption padding) */ 13 }; 14 15 enum ltc_pkcs_1_paddings 16 { 17 LTC_PKCS_1_V1_5 = 1, /* PKCS #1 v1.5 padding (\sa ltc_pkcs_1_v1_5_blocks) */ 18 LTC_PKCS_1_OAEP = 2, /* PKCS #1 v2.0 encryption padding */ 19 LTC_PKCS_1_PSS = 3, /* PKCS #1 v2.1 signature padding */ 20 LTC_PKCS_1_V1_5_NA1 = 4 /* PKCS #1 v1.5 padding - No ASN.1 (\sa ltc_pkcs_1_v1_5_blocks) */ 21 }; 22 23 int pkcs_1_mgf1( int hash_idx, 24 const unsigned char *seed, unsigned long seedlen, 25 unsigned char *mask, unsigned long masklen); 26 27 int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out); 28 int pkcs_1_os2ip(void *n, unsigned char *in, unsigned long inlen); 29 30 /* *** v1.5 padding */ 31 int pkcs_1_v1_5_encode(const unsigned char *msg, 32 unsigned long msglen, 33 int block_type, 34 unsigned long modulus_bitlen, 35 prng_state *prng, 36 int prng_idx, 37 unsigned char *out, 38 unsigned long *outlen); 39 40 int pkcs_1_v1_5_decode(const unsigned char *msg, 41 unsigned long msglen, 42 int block_type, 43 unsigned long modulus_bitlen, 44 unsigned char *out, 45 unsigned long *outlen, 46 int *is_valid); 47 48 /* *** v2.1 padding */ 49 int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, 50 const unsigned char *lparam, unsigned long lparamlen, 51 unsigned long modulus_bitlen, prng_state *prng, 52 int prng_idx, int hash_idx, 53 unsigned char *out, unsigned long *outlen); 54 55 int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen, 56 const unsigned char *lparam, unsigned long lparamlen, 57 unsigned long modulus_bitlen, int hash_idx, 58 unsigned char *out, unsigned long *outlen, 59 int *res); 60 61 int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen, 62 unsigned long saltlen, prng_state *prng, 63 int prng_idx, int hash_idx, 64 unsigned long modulus_bitlen, 65 unsigned char *out, unsigned long *outlen); 66 67 int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen, 68 const unsigned char *sig, unsigned long siglen, 69 unsigned long saltlen, int hash_idx, 70 unsigned long modulus_bitlen, int *res); 71 72 #endif /* LTC_PKCS_1 */ 73 74 /* ===> PKCS #5 -- Password Based Cryptography <=== */ 75 #ifdef LTC_PKCS_5 76 77 /* Algorithm #1 (PBKDF1) */ 78 int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 79 const unsigned char *salt, 80 int iteration_count, int hash_idx, 81 unsigned char *out, unsigned long *outlen); 82 83 /* Algorithm #1 (PBKDF1) - OpenSSL-compatible variant for arbitrarily-long keys. 84 Compatible with EVP_BytesToKey() */ 85 int pkcs_5_alg1_openssl(const unsigned char *password, 86 unsigned long password_len, 87 const unsigned char *salt, 88 int iteration_count, int hash_idx, 89 unsigned char *out, unsigned long *outlen); 90 91 /* Algorithm #2 (PBKDF2) */ 92 int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 93 const unsigned char *salt, unsigned long salt_len, 94 int iteration_count, int hash_idx, 95 unsigned char *out, unsigned long *outlen); 96 97 int pkcs_5_test (void); 98 #endif /* LTC_PKCS_5 */ 99 100