X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/e2f967aeff8b2c0b42d0b0a209f47543d61e48b1..HEAD:/symm/gaead.c diff --git a/symm/gaead.c b/symm/gaead.c index 45aeb614..d5130693 100644 --- a/symm/gaead.c +++ b/symm/gaead.c @@ -31,6 +31,27 @@ /*----- Main code ---------------------------------------------------------*/ +/* --- @gaead_szokcommon@ --- * + * + * Arguments: @const gcaead *aec@ = pointer to AEAD class + * @size_t nsz@, @size_t hsz@, @size_t msz@, @size_t tsz@ = + * nonce, header, message, and tag sizes + * + * Returns: Nonzero if the sizes are acceptable to the AEAD scheme in + * combination. + * + * Use: Generic implementation for sensible AEAD schemes. + */ + +int gaead_szokcommon(const gcaead *aec, + size_t nsz, size_t hsz, size_t msz, size_t tsz) +{ + if (keysz(nsz, aec->noncesz) != nsz) return (0); + if (keysz(tsz, aec->tagsz) != tsz) return (0); + if (hsz && (aec->f&AEADF_NOAAD)) return (0); + return (1); +} + /* --- @gaead_encrypt@ --- * * * Arguments: @const gaead_key *k@ = the AEAD key, already prepared