chiark / gitweb /
0a702b5513abd34edd0a25a903a7dc7d505d4328
[catacomb] / tlsprf.h
1 /* -*-c-*-
2  *
3  * $Id: tlsprf.h,v 1.2 2004/04/08 01:36:15 mdw Exp $
4  *
5  * The TLS pseudo-random function
6  *
7  * (c) 2001 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------*
11  *
12  * This file is part of Catacomb.
13  *
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.
18  *
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.
23  *
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,
27  * MA 02111-1307, USA.
28  */
29
30 #ifndef CATACOMB_TLSPRF_H
31 #define CATACOMB_TLSPRF_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #ifndef CATACOMB_GMAC_H
40 #  include "gmac.h"
41 #endif
42
43 #ifndef CATACOMB_GRAND_H
44 #  include "grand.h"
45 #endif
46
47 /*----- Data structures ---------------------------------------------------*/
48
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 */
58 } tlsdx_ctx;
59
60 typedef struct tlsprf_ctx {
61   tlsdx_ctx px, py;
62 } tlsprf_ctx;
63
64 /*----- The data expansion function ---------------------------------------*/
65
66 /* --- @tlsdx_init@ --- *
67  *
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
72  *
73  * Returns:     ---
74  *
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.
78  */
79
80 extern void tlsdx_init(tlsdx_ctx */*c*/, gmac */*m*/,
81                        const void */*sd*/, size_t /*sdsz*/);
82
83 /* --- @tlsdx_encrypt@ --- *
84  *
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
89  *
90  * Returns:     ---
91  *
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.
97  */
98
99 extern void tlsdx_encrypt(tlsdx_ctx */*c*/, const void */*src*/,
100                           void */*dest*/, size_t /*sz*/);
101
102 /* --- @tlsdx_free@ --- *
103  *
104  * Arguments:   @tlsdx_ctx *c@ = pointer to the context block
105  *
106  * Returns:     ---
107  *
108  * Use:         Frees a context for the TLS data expansion function
109  */
110
111 extern void tlsdx_free(tlsdx_ctx */*c*/);
112
113 /* ---@tlsdx_rand@ --- *
114  *
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
120  *
121  * Returns:     Pointer to generic random number generator interface.
122  *
123  * Use:         Creates a generic generator which does TLS data expansion.
124  */
125
126 extern grand *tlsdx_rand(const gcmac */*mc*/,
127                          const void */*k*/, size_t /*ksz*/,
128                          const void */*sd*/, size_t /*sdsz*/);
129
130 /* --- The actual very paranoid PRF ---------------------------------------*/
131
132 /* --- @tlsprf_init@ --- *
133  *
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
140  *
141  * Returns:     ---
142  *
143  * Use:         Initializes a TLS PRF context.
144  */
145
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*/);
150
151 /* --- @tlsprf_encrypt@ --- *
152  *
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
157  *
158  * Returns:     ---
159  *
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.
165  */
166
167 extern void tlsprf_encrypt(tlsprf_ctx */*c*/,
168                            const void */*src*/, void */*dest*/,
169                            size_t /*sz*/);
170
171 /* --- @tlsprf_free@ --- *
172  *
173  * Arguments:   @tlsprf_ctx *c@ = pointer to a context
174  *
175  * Returns:     ---
176  *
177  * Use:         Frees a TLS PRF context.
178  */
179
180 extern void tlsprf_free(tlsprf_ctx */*c*/);
181
182 /* ---@tlsprf_rand@ --- *
183  *
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
189  *
190  * Returns:     Pointer to generic random number generator interface.
191  *
192  * Use:         Creates a generic generator which does TLS data expansion.
193  */
194
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*/);
198
199 /*----- That's all, folks -------------------------------------------------*/
200
201 #ifdef __cplusplus
202   }
203 #endif
204
205 #endif