3 * $Id: tlsprf.h,v 1.2 2004/04/08 01:36:15 mdw Exp $
5 * The TLS pseudo-random function
7 * (c) 2001 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 #ifndef CATACOMB_TLSPRF_H
31 #define CATACOMB_TLSPRF_H
37 /*----- Header files ------------------------------------------------------*/
39 #ifndef CATACOMB_GMAC_H
43 #ifndef CATACOMB_GRAND_H
47 /*----- Data structures ---------------------------------------------------*/
49 typedef struct tlsdx_ctx {
50 gmac *k; /* The MAC key to use */
51 size_t hashsz; /* Size of hash outputs */
52 ghash *i, *o; /* Inner and outer hash contexts */
53 const octet *sd; /* Pointer to seed buffer */
54 size_t sdsz; /* Size of the seed buffer */
55 octet *p; /* Pointer to buffered output */
56 size_t sz; /* Bytes remaining in buffer */
57 octet *ai; /* Pointer to inner result */
60 typedef struct tlsprf_ctx {
64 /*----- The data expansion function ---------------------------------------*/
66 /* --- @tlsdx_init@ --- *
68 * Arguments: @tlsdx_ctx *c@ = pointer to a context
69 * @gmac *m@ = pointer to a generic MAC instance
70 * @const void *sd@ = pointer to the seed block
71 * @size_t sdsz@ = size of the seed block
75 * Use: Initializes a context for the TLS data expansion function.
76 * This doesn't take ownership of the MAC instance or the seed
77 * memory, nor does it allocate copies.
80 extern void tlsdx_init(tlsdx_ctx */*c*/, gmac */*m*/,
81 const void */*sd*/, size_t /*sdsz*/);
83 /* --- @tlsdx_encrypt@ --- *
85 * Arguments: @tlsdx_ctx *c@ = pointer to a context
86 * @const void *src@ = pointer to source data
87 * @void *dest@ = pointer to destination buffer
88 * @size_t sz@ = size of buffer
92 * Use: Encrypts data using the TLS data expansion function. If the
93 * destination pointer is null, the generator is spun and no
94 * output is produced; if the source pointer is null, raw output
95 * from the generator is written; otherwise, the source data is
96 * XORed with the generator output.
99 extern void tlsdx_encrypt(tlsdx_ctx */*c*/, const void */*src*/,
100 void */*dest*/, size_t /*sz*/);
102 /* --- @tlsdx_free@ --- *
104 * Arguments: @tlsdx_ctx *c@ = pointer to the context block
108 * Use: Frees a context for the TLS data expansion function
111 extern void tlsdx_free(tlsdx_ctx */*c*/);
113 /* ---@tlsdx_rand@ --- *
115 * Arguments: @const gcmac *mc@ = MAC function to use
116 * @const void *k@ = pointer to the key material
117 * @size_t ksz@ = size of the key material
118 * @const void *sd@ = pointer to the seed material
119 * @size_t sdsz@ = size of the seed material
121 * Returns: Pointer to generic random number generator interface.
123 * Use: Creates a generic generator which does TLS data expansion.
126 extern grand *tlsdx_rand(const gcmac */*mc*/,
127 const void */*k*/, size_t /*ksz*/,
128 const void */*sd*/, size_t /*sdsz*/);
130 /* --- The actual very paranoid PRF ---------------------------------------*/
132 /* --- @tlsprf_init@ --- *
134 * Arguments: @tlsprf_ctx *c@ = pointer to context block
135 * @const gcmac *mcx, *mcy@ = left and right MAC functions
136 * @const void *k@ = pointer to the key material
137 * @size_t ksz@ = size of the key material
138 * @const void *sd@ = pointer to the seed material
139 * @size_t sdsz@ = size of the seed material
143 * Use: Initializes a TLS PRF context.
146 extern void tlsprf_init(tlsprf_ctx */*c*/,
147 const gcmac */*mcx*/, const gcmac */*mcy*/,
148 const void */*k*/, size_t /*ksz*/,
149 const void */*sd*/, size_t /*sdsz*/);
151 /* --- @tlsprf_encrypt@ --- *
153 * Arguments: @tlsprf_ctx *c@ = pointer to a context
154 * @const void *src@ = pointer to source data
155 * @void *dest@ = pointer to destination buffer
156 * @size_t sz@ = size of buffer
160 * Use: Encrypts data using the TLS pseudo-random function. If the
161 * destination pointer is null, the generator is spun and no
162 * output is produced; if the source pointer is null, raw output
163 * from the generator is written; otherwise, the source data is
164 * XORed with the generator output.
167 extern void tlsprf_encrypt(tlsprf_ctx */*c*/,
168 const void */*src*/, void */*dest*/,
171 /* --- @tlsprf_free@ --- *
173 * Arguments: @tlsprf_ctx *c@ = pointer to a context
177 * Use: Frees a TLS PRF context.
180 extern void tlsprf_free(tlsprf_ctx */*c*/);
182 /* ---@tlsprf_rand@ --- *
184 * Arguments: @const gcmac *mcx, *mcy@ = MAC function to use
185 * @const void *k@ = pointer to the key material
186 * @size_t ksz@ = size of the key material
187 * @const void *sd@ = pointer to the seed material
188 * @size_t sdsz@ = size of the seed material
190 * Returns: Pointer to generic random number generator interface.
192 * Use: Creates a generic generator which does TLS data expansion.
195 extern grand *tlsprf_rand(const gcmac */*mcx*/, const gcmac */*mcy*/,
196 const void */*k*/, size_t /*ksz*/,
197 const void */*sd*/, size_t /*sdsz*/);
199 /*----- That's all, folks -------------------------------------------------*/