summaryrefslogtreecommitdiff
path: root/lib/pk.c
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-03-16 11:38:58 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-05-29 08:23:49 +0200
commit9e5452193c3510102801fd86b6e65d37b5dc1012 (patch)
tree1c401b3900c8a6f3ffac58ad839266e8c228f941 /lib/pk.c
parent03c811b7f9a280182b486473567a0b93fe1dc291 (diff)
downloadgnutls-9e5452193c3510102801fd86b6e65d37b5dc1012.tar.gz
x509: implement RSA-PSS signature scheme
This patch enables RSA-PSS signature scheme in the X.509 functions and certtool. When creating RSA-PSS signature, there are 3 different scenarios: a. both a private key and a certificate are RSA-PSS b. the private key is RSA, while the certificate is RSA-PSS c. both the private key and the certificate are RSA For (a) and (b), the RSA-PSS parameters are read from the certificate. Any conflicts in parameters between the private key and the certificate are reported as an error. For (c), the sign functions, such as gnutls_x509_crt_privkey_sign() or gnutls_privkey_sign_data(), shall be instructed to generate an RSA-PSS signature. This can be done with the new flag GNUTLS_PRIVKEY_SIGN_FLAG_RSA_PSS. Verification is similar to signing, except for the case (c), use the flag GNUTLS_VERIFY_USE_RSA_PSS instead of GNUTLS_PRIVKEY_SIGN_FLAG_RSA_PSS. From the command line, certtool has a couple of new options: --rsa-pss and --rsa-pss-sign. The --rsa-pss option indicates that the generated private key or certificate is restricted to RSA-PSS, while the --rsa-pss-sign option indicates that the generated certificate is signed with RSA-PSS. For simplicity, there is no means of choosing arbitrary salt length. When it is not given by a private key or a certificate, it is automatically calculated from the underlying hash algorithm and the RSA modulus bits. [minor naming changes by nmav] Signed-off-by: Daiki Ueno <dueno@redhat.com> Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/pk.c')
-rw-r--r--lib/pk.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/pk.c b/lib/pk.c
index c2c62886f7..0e6443a74d 100644
--- a/lib/pk.c
+++ b/lib/pk.c
@@ -332,6 +332,8 @@ int _gnutls_pk_params_copy(gnutls_pk_params_st * dst,
}
dst->palgo = src->palgo;
+ memcpy(&dst->sign, &src->sign, sizeof(gnutls_x509_spki_st));
+
return 0;
fail:
@@ -374,6 +376,24 @@ void gnutls_pk_params_clear(gnutls_pk_params_st * p)
}
}
+unsigned
+_gnutls_find_rsa_pss_salt_size(unsigned bits, const mac_entry_st *me,
+ unsigned salt_size)
+{
+ unsigned max_salt_size, digest_size;
+
+ digest_size = _gnutls_hash_get_algo_len(me);
+ max_salt_size = (bits + 7) / 8 - digest_size - 2;
+
+ if (salt_size < digest_size)
+ salt_size = digest_size;
+
+ if (salt_size > max_salt_size)
+ salt_size = max_salt_size;
+
+ return salt_size;
+}
+
/* Writes the digest information and the digest in a DER encoded
* structure. The digest info is allocated and stored into the info structure.
*/
@@ -596,7 +616,7 @@ _gnutls_params_get_rsa_raw(const gnutls_pk_params_st* params,
return GNUTLS_E_INVALID_REQUEST;
}
- if (params->algo != GNUTLS_PK_RSA) {
+ if (!GNUTLS_PK_IS_RSA(params->algo)) {
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
}
@@ -890,6 +910,7 @@ pk_prepare_hash(gnutls_pk_algorithm_t pk,
_gnutls_free_datum(&old_digest);
break;
+ case GNUTLS_PK_RSA_PSS:
case GNUTLS_PK_DSA:
case GNUTLS_PK_EC:
break;