-/* $OpenBSD: ech_key.c,v 1.20 2023/07/01 14:39:34 tb Exp $ */
+/* $OpenBSD: ech_key.c,v 1.21 2023/07/01 14:48:01 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
const BIGNUM *priv_key;
const EC_GROUP* group;
int ret = -1;
- size_t buflen, len;
unsigned char *buf = NULL;
+ int buflen, len;
if (outlen > INT_MAX) {
/* Sort of, anyway. */
ECDHerror(ERR_R_MALLOC_FAILURE);
goto err;
}
-
- memset(buf, 0, buflen - len);
- if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {
+ if (BN_bn2binpad(x, buf, buflen) != buflen) {
ECDHerror(ERR_R_BN_LIB);
goto err;
}