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