3 * General block cipher utilities
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
34 /*----- Main code ---------------------------------------------------------*/
38 * Arguments: @size_t sz@ = a proposed key size, or zero
39 * @const octet *ksz@ = pointer to key size table
43 * Use: Returns a sensible key size. If @sz@ is nonzero, it is
44 * interpreted as an amount (in bytes) of key material which the
45 * caller has available, and the return value is either the
46 * largest allowable key size less than or equal to the caller's
47 * size, or zero if there is no valid key length small enough.
48 * If @sz@ is zero, the function returns a `recommended' key
52 size_t keysz(size_t sz, const octet *ksz)
56 else switch (ksz[0]) {
64 if (ksz[3] && sz > ksz[3])
69 for (ksz++; *ksz; ksz++) {
70 if (sz >= *ksz && q < *ksz)
77 assert(((void)"bad key size table", 0));
81 /*----- That's all, folks -------------------------------------------------*/