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 #include "tomcrypt_private.h"
11 
12 /**
13   @file rsa_sign_saltlen_get.c
14   Retrieve the maximum size of the salt, Steffen Jaeckel.
15 */
16 
17 #ifdef LTC_MRSA
18 
19 /**
20   Retrieve the maximum possible size of the salt when creating a PKCS#1 PSS signature.
21   @param padding    Type of padding (LTC_PKCS_1_PSS only)
22   @param hash_idx   The index of the desired hash
23   @param key        The RSA key
24   @return The maximum salt length in bytes or INT_MAX on error.
25 */
rsa_sign_saltlen_get_max_ex(int padding,int hash_idx,const rsa_key * key)26 int rsa_sign_saltlen_get_max_ex(int padding, int hash_idx, const rsa_key *key)
27 {
28   int ret = INT_MAX;
29   LTC_ARGCHK(key != NULL);
30 
31   if ((hash_is_valid(hash_idx) == CRYPT_OK) &&
32       (padding == LTC_PKCS_1_PSS))
33   {
34     ret = rsa_get_size(key);
35     if (ret < INT_MAX)
36     {
37       ret -= (hash_descriptor[hash_idx]->hashsize + 2);
38     } /* if */
39   } /* if */
40 
41   return ret;
42 }
43 
44 #endif
45 
46 /* ref:         $Format:%D$ */
47 /* git commit:  $Format:%H$ */
48 /* commit time: $Format:%ai$ */
49