3 * $Id: keysz.c,v 1.1 2000/06/17 11:27:52 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2000/06/17 11:27:52 mdw
34 * Key size table interpretation.
38 /*----- Header files ------------------------------------------------------*/
44 /*----- Main code ---------------------------------------------------------*/
48 * Arguments: @size_t sz@ = a proposed key size, or zero
49 * @const octet *ksz@ = pointer to key size table
53 * Use: Returns a sensible key size. If @sz@ is nonzero, it is
54 * interpreted as an amount (in bytes) of key material which the
55 * caller has available, and the return value is either the
56 * largest allowable key size less than or equal to the caller's
57 * size, or zero if there is no valid key length small enough.
58 * If @sz@ is zero, the function returns a `recommended' key
62 size_t keysz(size_t sz
, const octet
*ksz
)
66 else switch (ksz
[0]) {
74 if (ksz
[3] && sz
> ksz
[3])
79 for (ksz
++; *ksz
; ksz
++) {
80 if (sz
>= *ksz
&& q
< *ksz
)
87 assert(((void)"bad key size table", 0));
91 /*----- That's all, folks -------------------------------------------------*/