1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

If EVP_CIPHER_CTX_ctrl(3) is called on EVP_chacha20_poly1305(3)

with an unsupported control command, return -1 rather than 0
to the caller to indicate the error because in general, these
control hooks ought to return -1 for unsupported control commands
and 0 for other errors, for example other invalid arguments.

Not a big deal because this change does not change when operations
succeed or fail, and because callers are unlikely to pass unsupported
control commands in the first place.  The only functional change is that
if a calling program inspects the ERR(3) stack after this failure,
it will now find the correct error code rather than nothing.
Even that wasn't a huge problem because for most EVP_CIPHER control
failures, getting no reason for the error is the usual situation.
Then again, giving the reason when easily possible may occasionally
be useful.  OpenSSL also returns -1 in this case, so it also helps
compatibility a tiny bit.

Found while auditing the return values of all the EVP_CIPHER
control hooks in our tree.  This was the only fishy one i found.

OK tb@
This commit is contained in:
schwarze 2024-12-20 20:05:29 +00:00
parent 3458005deb
commit 4ac9059474

View File

@ -1,4 +1,4 @@
/* $OpenBSD: e_chacha20poly1305.c,v 1.36 2024/05/22 14:02:08 tb Exp $ */
/* $OpenBSD: e_chacha20poly1305.c,v 1.37 2024/12/20 20:05:29 schwarze Exp $ */
/*
* Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
@ -592,7 +592,7 @@ chacha20_poly1305_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
return 1;
}
return 0;
return -1;
}
static const EVP_CIPHER cipher_chacha20_poly1305 = {