2 * Copyright (C) 1998, 1999 D. Hugh Redelmeier.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * RCSID $Id: crypto.h,v 1.13 1999/12/13 00:40:50 dhr Exp $
17 #include <gmp.h> /* GNU MP library */
19 extern void init_crypto(void);
21 /* Oakley group descriptions */
23 extern MP_INT groupgenerator; /* MODP group generator (2) */
25 struct oakley_group_desc {
31 extern const struct oakley_group_desc unset_group; /* magic signifier */
32 extern const struct oakley_group_desc *lookup_group(u_int16_t group);
33 #define OAKLEY_GROUP_SIZE 6
34 extern const struct oakley_group_desc oakley_group[OAKLEY_GROUP_SIZE];
36 /* unification of cryptographic encoding/decoding algorithms
37 * The IV is taken from and returned to st->st_new_iv.
38 * This allows the old IV to be retained.
39 * Use update_iv to commit to the new IV (for example, once a packet has
43 #define MAX_OAKLEY_KEY_LEN0 (3 * DES_CBC_BLOCK_SIZE)
44 #define MAX_OAKLEY_KEY_LEN (256/BITS_PER_BYTE)
46 struct state; /* forward declaration, dammit */
50 struct encrypt_desc *crypto_get_encrypter(int alg);
51 struct hash_desc *crypto_get_hasher(int alg);
52 void crypto_cbc_encrypt(const struct encrypt_desc *e, bool enc, u_int8_t *buf, size_t size, struct state *st);
53 #define update_iv(st) memcpy((st)->st_iv, (st)->st_new_iv \
54 , (st)->st_iv_len = (st)->st_new_iv_len)
56 /* unification of cryptographic hashing mechanisms */
62 char ctx_sha256[108]; /* This is _ugly_ [TM], but avoids */
63 char ctx_sha512[212]; /* header coupling (is checked at runtime */
67 * Note that hmac_ctx can be (and is) copied since there are
68 * no persistent pointers into it.
72 const struct hash_desc *h; /* underlying hash function */
73 size_t hmac_digest_size; /* copy of h->hash_digest_size */
74 union hash_ctx hash_ctx; /* ctx for hash function */
75 u_char buf1[HMAC_BUFSIZE], buf2[HMAC_BUFSIZE];
78 extern void hmac_init(
80 const struct hash_desc *h,
84 #define hmac_init_chunk(ctx, h, ch) hmac_init((ctx), (h), (ch).ptr, (ch).len)
86 extern void hmac_reinit(struct hmac_ctx *ctx); /* saves recreating pads */
88 extern void hmac_update(
93 #define hmac_update_chunk(ctx, ch) hmac_update((ctx), (ch).ptr, (ch).len)
95 extern void hmac_final(u_char *output, struct hmac_ctx *ctx);
97 #define hmac_final_chunk(ch, name, ctx) { \
99 (ch).len = (ctx)->hmac_digest_size; \
100 (ch).ptr = alloc_bytes((ch).len, name); \
101 hmac_final((ch).ptr, (ctx)); \