From: Hongbo Li <herbert.tencent@gmail.com>
To: zohar@linux.ibm.com, herberthbli@tencent.com
Cc: linux-integrity@vger.kernel.org, herbert@gondor.apana.org.au,
Hongbo Li <herbert.tencent@gmail.com>
Subject: [PATCH] rsa: add pss encoding support
Date: Tue, 6 Apr 2021 21:32:54 +0800 [thread overview]
Message-ID: <1617715974-29632-1-git-send-email-herbert.tencent@gmail.com> (raw)
This patch adds support for rsa with pss encoding.
Add two new params: encoding and saltlen.
Signed-off-by: Hongbo Li <herbert.tencent@gmail.com>
---
src/evmctl.c | 19 +++++++++++++++++--
src/imaevm.h | 2 ++
src/libimaevm.c | 22 ++++++++++++++++++++++
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/src/evmctl.c b/src/evmctl.c
index 1815f55..bff1dc2 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2440,6 +2440,8 @@ static void usage(void)
printf(
"\n"
" -a, --hashalgo sha1 (default), sha224, sha256, sha384, sha512, streebog256, streebog512\n"
+ " -e, --encoding pkcs1 (default), pss\n"
+ " -l, --saltlen pss salt lenght, digest length is used by default\n"
" -s, --imasig make IMA signature\n"
" -d, --imahash make IMA hash\n"
" -f, --sigfile store IMA signature in .sig file instead of xattr\n"
@@ -2500,6 +2502,8 @@ static struct option opts[] = {
{"imasig", 0, 0, 's'},
{"imahash", 0, 0, 'd'},
{"hashalgo", 1, 0, 'a'},
+ {"encoding", 1, 0, 'e'},
+ {"saltlen", 1, 0, 'l'},
{"pass", 2, 0, 'p'},
{"sigfile", 0, 0, 'f'},
{"uuid", 2, 0, 'u'},
@@ -2567,7 +2571,7 @@ static char *get_password(void)
int main(int argc, char *argv[])
{
- int err = 0, c, lind;
+ int err = 0, c, lind, val;
ENGINE *eng = NULL;
#if !(OPENSSL_VERSION_NUMBER < 0x10100000)
@@ -2581,7 +2585,7 @@ int main(int argc, char *argv[])
g_argc = argc;
while (1) {
- c = getopt_long(argc, argv, "hvnsda:op::fu::k:t:ri", opts, &lind);
+ c = getopt_long(argc, argv, "hvnsda:e:l:op::fu::k:t:ri", opts, &lind);
if (c == -1)
break;
@@ -2607,6 +2611,17 @@ int main(int argc, char *argv[])
case 'a':
imaevm_params.hash_algo = optarg;
break;
+ case 'e':
+ imaevm_params.encoding = optarg;
+ break;
+ case 'l':
+ val = atoi(optarg);
+ if (val <= 0) {
+ log_err("invalid pss salt len\n");
+ exit(1);
+ }
+ imaevm_params.saltlen = val;
+ break;
case 'p':
if (optarg)
imaevm_params.keypass = optarg;
diff --git a/src/imaevm.h b/src/imaevm.h
index 4503919..4e2dc3a 100644
--- a/src/imaevm.h
+++ b/src/imaevm.h
@@ -194,6 +194,8 @@ struct libimaevm_params {
int verbose;
int x509;
const char *hash_algo;
+ const char *encoding;
+ uint32_t saltlen;
const char *keyfile;
const char *keypass;
};
diff --git a/src/libimaevm.c b/src/libimaevm.c
index fa6c278..1bf6c67 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -530,6 +530,13 @@ static int verify_hash_v2(const char *file, const unsigned char *hash, int size,
st = "EVP_PKEY_CTX_set_signature_md";
if (!EVP_PKEY_CTX_set_signature_md(ctx, md))
goto err;
+
+ if (imaevm_params.encoding &&
+ !strcmp(imaevm_params.encoding, "pss")) {
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0)
+ goto err;
+ }
+
st = "EVP_PKEY_verify";
ret = EVP_PKEY_verify(ctx, sig + sizeof(*hdr),
siglen - sizeof(*hdr), hash, size);
@@ -895,6 +902,7 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
size_t sigsize;
const char *st;
uint32_t keyid;
+ int saltlen;
if (!hash) {
log_err("sign_hash_v2: hash is null\n");
@@ -947,6 +955,20 @@ static int sign_hash_v2(const char *algo, const unsigned char *hash,
st = "EVP_PKEY_CTX_set_signature_md";
if (!EVP_PKEY_CTX_set_signature_md(ctx, md))
goto err;
+
+ if (imaevm_params.encoding &&
+ !strcmp(imaevm_params.encoding, "pss")) {
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) <= 0)
+ goto err;
+
+ if (imaevm_params.saltlen)
+ saltlen = imaevm_params.saltlen;
+ else
+ saltlen = -1;
+ if (EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen) <= 0)
+ goto err;
+ }
+
st = "EVP_PKEY_sign";
sigsize = MAX_SIGNATURE_SIZE - sizeof(struct signature_v2_hdr) - 1;
if (!EVP_PKEY_sign(ctx, hdr->sig, &sigsize, hash, size))
--
1.8.3.1
reply other threads:[~2021-04-06 13:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1617715974-29632-1-git-send-email-herbert.tencent@gmail.com \
--to=herbert.tencent@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=herberthbli@tencent.com \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.