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