| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Generic MAC function interface |
| 4 | * |
| 5 | * (c) 1999 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of Catacomb. |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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, |
| 25 | * MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | #ifndef CATACOMB_GMAC_H |
| 29 | #define CATACOMB_GMAC_H |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /*----- Header files ------------------------------------------------------*/ |
| 36 | |
| 37 | #include <stddef.h> |
| 38 | |
| 39 | #ifndef CATACOMB_GCIPHER_H |
| 40 | # include "gcipher.h" |
| 41 | #endif |
| 42 | |
| 43 | #ifndef CATACOMB_GHASH_H |
| 44 | # include "ghash.h" |
| 45 | #endif |
| 46 | |
| 47 | /*----- Generic MAC function interface ------------------------------------*/ |
| 48 | |
| 49 | typedef struct gmac { |
| 50 | const struct gmac_ops *ops; /* Pointer to MAC operations */ |
| 51 | } gmac; |
| 52 | |
| 53 | typedef struct gmac_ops { |
| 54 | const struct gcmac *c; /* Pointer to MAC class */ |
| 55 | ghash *(*init)(gmac */*m*/); /* Create keyed hash instance */ |
| 56 | void (*destroy)(gmac */*m*/); /* Destroy MAC key block */ |
| 57 | } gmac_ops; |
| 58 | |
| 59 | typedef struct gcmac { |
| 60 | const char *name; /* Name of the MAC function */ |
| 61 | size_t hashsz; /* Size of output hash */ |
| 62 | const octet *keysz; /* Key size options */ |
| 63 | gmac *(*key)(const void */*k*/, size_t /*sz*/); /* Create key */ |
| 64 | } gcmac; |
| 65 | |
| 66 | #define GM_KEY(cm, k, ksz) (cm)->key((k), (ksz)) |
| 67 | #define GM_CLASS(km) (km)->ops->c |
| 68 | #define GM_INIT(km) (km)->ops->init((km)) |
| 69 | #define GM_DESTROY(km) (km)->ops->destroy((km)) |
| 70 | |
| 71 | /*----- Tables ------------------------------------------------------------*/ |
| 72 | |
| 73 | extern const gcmac *const gmactab[]; |
| 74 | |
| 75 | /* --- @gmac_byname@ --- * |
| 76 | * |
| 77 | * Arguments: @const char *p@ = pointer to name string |
| 78 | * |
| 79 | * Returns: The named cipher class, or null. |
| 80 | */ |
| 81 | |
| 82 | extern const gcmac *gmac_byname(const char */*p*/); |
| 83 | |
| 84 | /*----- That's all, folks -------------------------------------------------*/ |
| 85 | |
| 86 | #ifdef __cplusplus |
| 87 | } |
| 88 | #endif |
| 89 | |
| 90 | #endif |