summaryrefslogtreecommitdiff
path: root/ssh-pkcs11.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-21 00:47:34 +0000
committerDamien Miller <djm@mindrot.org>2019-01-21 11:48:45 +1100
commit632976418d60b7193597bbc6ac7ca33981a41aab (patch)
tree1b0a4984b289f6e516b897cbd65731e25310facb /ssh-pkcs11.c
parent5de6ac2bad11175135d9b819b3546db0ca0b4878 (diff)
downloadopenssh-git-632976418d60b7193597bbc6ac7ca33981a41aab.tar.gz
upstream: use ECDSA_SIG_set0() instead of poking signature values into
structure directly; the latter works on LibreSSL but not on OpenSSL. From portable. OpenBSD-Commit-ID: 5b22a1919d9cee907d3f8a029167f70a481891c6
Diffstat (limited to 'ssh-pkcs11.c')
-rw-r--r--ssh-pkcs11.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
index 41992ceb..7dc82897 100644
--- a/ssh-pkcs11.c
+++ b/ssh-pkcs11.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-pkcs11.c,v 1.36 2019/01/20 23:12:35 djm Exp $ */
+/* $OpenBSD: ssh-pkcs11.c,v 1.37 2019/01/21 00:47:34 djm Exp $ */
/*
* Copyright (c) 2010 Markus Friedl. All rights reserved.
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
@@ -420,6 +420,7 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
CK_RV rv;
ECDSA_SIG *ret = NULL;
u_char *sig;
+ BIGNUM *r = NULL, *s = NULL;
if ((k11 = EC_KEY_get_ex_data(ec, 0)) == NULL) {
ossl_error("EC_KEY_get_key_method_data failed for ec");
@@ -452,14 +453,24 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
error("ECDSA_SIG_new failed");
goto done;
}
- if (BN_bin2bn(sig, bnlen, ret->r) == NULL ||
- BN_bin2bn(sig+bnlen, bnlen, ret->s) == NULL) {
+ if ((r = BN_bin2bn(sig, bnlen, NULL)) == NULL ||
+ (s = BN_bin2bn(sig+bnlen, bnlen, NULL)) == NULL) {
ossl_error("d2i_ECDSA_SIG failed");
ECDSA_SIG_free(ret);
ret = NULL;
goto done;
}
+ if (!ECDSA_SIG_set0(ret, r, s)) {
+ error("%s: ECDSA_SIG_set0 failed", __func__);
+ ECDSA_SIG_free(ret);
+ ret = NULL;
+ goto done;
+ }
+ r = s = NULL; /* now owned by ret */
+ /* success */
done:
+ BN_free(r);
+ BN_free(s);
free(sig);
return (ret);