summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2015-09-13 14:11:57 +0000
committerjsing <>2015-09-13 14:11:57 +0000
commit533a2cdb71a16eafbc7aced4709154605f68cd6d (patch)
treef5146291b85e2c9f854ab0654b26a865d963724c /src/lib
parent71beab70d6c6c4c2fec45ea25b07f5c52fe425d4 (diff)
downloadopenbsd-533a2cdb71a16eafbc7aced4709154605f68cd6d.tar.gz
openbsd-533a2cdb71a16eafbc7aced4709154605f68cd6d.tar.bz2
openbsd-533a2cdb71a16eafbc7aced4709154605f68cd6d.zip
Only check for key truncation if no KDF function is being used.
ok beck@ miod@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ecdh/ech_key.c8
-rw-r--r--src/lib/libssl/src/crypto/ecdh/ech_key.c8
2 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c
index 7202c497cf..e695b0b9ad 100644
--- a/src/lib/libcrypto/ecdh/ech_key.c
+++ b/src/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.4 2015/09/13 12:27:14 jsing Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.5 2015/09/13 14:11:57 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -162,7 +162,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
162 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); 162 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR);
163 goto err; 163 goto err;
164 } 164 }
165 if (outlen < buflen) { 165 if (KDF == NULL && outlen < buflen) {
166 /* The resulting key would be truncated. */ 166 /* The resulting key would be truncated. */
167 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KEY_TRUNCATION); 167 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KEY_TRUNCATION);
168 goto err; 168 goto err;
@@ -178,14 +178,14 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
178 goto err; 178 goto err;
179 } 179 }
180 180
181 if (KDF != 0) { 181 if (KDF != NULL) {
182 if (KDF(buf, buflen, out, &outlen) == NULL) { 182 if (KDF(buf, buflen, out, &outlen) == NULL) {
183 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED); 183 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED);
184 goto err; 184 goto err;
185 } 185 }
186 ret = outlen; 186 ret = outlen;
187 } else { 187 } else {
188 /* No KDF, just copy as much as we can and zero the rest. */ 188 /* No KDF, just copy out the key and zero the rest. */
189 if (outlen > buflen) { 189 if (outlen > buflen) {
190 memset(out + buflen, 0, outlen - buflen); 190 memset(out + buflen, 0, outlen - buflen);
191 outlen = buflen; 191 outlen = buflen;
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_key.c b/src/lib/libssl/src/crypto/ecdh/ech_key.c
index 7202c497cf..e695b0b9ad 100644
--- a/src/lib/libssl/src/crypto/ecdh/ech_key.c
+++ b/src/lib/libssl/src/crypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.4 2015/09/13 12:27:14 jsing Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.5 2015/09/13 14:11:57 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -162,7 +162,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
162 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); 162 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR);
163 goto err; 163 goto err;
164 } 164 }
165 if (outlen < buflen) { 165 if (KDF == NULL && outlen < buflen) {
166 /* The resulting key would be truncated. */ 166 /* The resulting key would be truncated. */
167 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KEY_TRUNCATION); 167 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KEY_TRUNCATION);
168 goto err; 168 goto err;
@@ -178,14 +178,14 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
178 goto err; 178 goto err;
179 } 179 }
180 180
181 if (KDF != 0) { 181 if (KDF != NULL) {
182 if (KDF(buf, buflen, out, &outlen) == NULL) { 182 if (KDF(buf, buflen, out, &outlen) == NULL) {
183 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED); 183 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED);
184 goto err; 184 goto err;
185 } 185 }
186 ret = outlen; 186 ret = outlen;
187 } else { 187 } else {
188 /* No KDF, just copy as much as we can and zero the rest. */ 188 /* No KDF, just copy out the key and zero the rest. */
189 if (outlen > buflen) { 189 if (outlen > buflen) {
190 memset(out + buflen, 0, outlen - buflen); 190 memset(out + buflen, 0, outlen - buflen);
191 outlen = buflen; 191 outlen = buflen;