d83a82be |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: tlsprf.h,v 1.1 2001/04/04 20:10:52 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 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: tlsprf.h,v $ |
33 | * Revision 1.1 2001/04/04 20:10:52 mdw |
34 | * Add support for the TLS pseudo-random function. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CATACOMB_TLSPRF_H |
39 | #define CATACOMB_TLSPRF_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #ifndef CATACOMB_GMAC_H |
48 | # include "gmac.h" |
49 | #endif |
50 | |
51 | #ifndef CATACOMB_GRAND_H |
52 | # include "grand.h" |
53 | #endif |
54 | |
55 | /*----- Data structures ---------------------------------------------------*/ |
56 | |
57 | typedef struct tlsdx_ctx { |
58 | gmac *k; /* The MAC key to use */ |
59 | size_t hashsz; /* Size of hash outputs */ |
60 | ghash *i, *o; /* Inner and outer hash contexts */ |
61 | const octet *sd; /* Pointer to seed buffer */ |
62 | size_t sdsz; /* Size of the seed buffer */ |
63 | octet *p; /* Pointer to buffered output */ |
64 | size_t sz; /* Bytes remaining in buffer */ |
65 | octet *ai; /* Pointer to inner result */ |
66 | } tlsdx_ctx; |
67 | |
68 | typedef struct tlsprf_ctx { |
69 | tlsdx_ctx px, py; |
70 | } tlsprf_ctx; |
71 | |
72 | /*----- The data expansion function ---------------------------------------*/ |
73 | |
74 | /* --- @tlsdx_init@ --- * |
75 | * |
76 | * Arguments: @tlsdx_ctx *c@ = pointer to a context |
77 | * @gmac *m@ = pointer to a generic MAC instance |
78 | * @const void *sd@ = pointer to the seed block |
79 | * @size_t sdsz@ = size of the seed block |
80 | * |
81 | * Returns: --- |
82 | * |
83 | * Use: Initializes a context for the TLS data expansion function. |
84 | * This doesn't take ownership of the MAC instance or the seed |
85 | * memory, nor does it allocate copies. |
86 | */ |
87 | |
88 | extern void tlsdx_init(tlsdx_ctx */*c*/, gmac */*m*/, |
89 | const void */*sd*/, size_t /*sdsz*/); |
90 | |
91 | /* --- @tlsdx_encrypt@ --- * |
92 | * |
93 | * Arguments: @tlsdx_ctx *c@ = pointer to a context |
94 | * @const void *src@ = pointer to source data |
95 | * @void *dest@ = pointer to destination buffer |
96 | * @size_t sz@ = size of buffer |
97 | * |
98 | * Returns: --- |
99 | * |
100 | * Use: Encrypts data using the TLS data expansion function. If the |
101 | * destination pointer is null, the generator is spun and no |
102 | * output is produced; if the source pointer is null, raw output |
103 | * from the generator is written; otherwise, the source data is |
104 | * XORed with the generator output. |
105 | */ |
106 | |
107 | extern void tlsdx_encrypt(tlsdx_ctx */*c*/, const void */*src*/, |
108 | void */*dest*/, size_t /*sz*/); |
109 | |
110 | /* --- @tlsdx_free@ --- * |
111 | * |
112 | * Arguments: @tlsdx_ctx *c@ = pointer to the context block |
113 | * |
114 | * Returns: --- |
115 | * |
116 | * Use: Frees a context for the TLS data expansion function |
117 | */ |
118 | |
119 | extern void tlsdx_free(tlsdx_ctx */*c*/); |
120 | |
121 | /* ---@tlsdx_rand@ --- * |
122 | * |
123 | * Arguments: @const gcmac *mc@ = MAC function to use |
124 | * @const void *k@ = pointer to the key material |
125 | * @size_t ksz@ = size of the key material |
126 | * @const void *sd@ = pointer to the seed material |
127 | * @size_t sdsz@ = size of the seed material |
128 | * |
129 | * Returns: Pointer to generic random number generator interface. |
130 | * |
131 | * Use: Creates a generic generator which does TLS data expansion. |
132 | */ |
133 | |
134 | extern grand *tlsdx_rand(const gcmac */*mc*/, |
135 | const void */*k*/, size_t /*ksz*/, |
136 | const void */*sd*/, size_t /*sdsz*/); |
137 | |
138 | /* --- The actual very paranoid PRF ---------------------------------------*/ |
139 | |
140 | /* --- @tlsprf_init@ --- * |
141 | * |
142 | * Arguments: @tlsprf_ctx *c@ = pointer to context block |
143 | * @const gcmac *mcx, *mcy@ = left and right MAC functions |
144 | * @const void *k@ = pointer to the key material |
145 | * @size_t ksz@ = size of the key material |
146 | * @const void *sd@ = pointer to the seed material |
147 | * @size_t sdsz@ = size of the seed material |
148 | * |
149 | * Returns: --- |
150 | * |
151 | * Use: Initializes a TLS PRF context. |
152 | */ |
153 | |
154 | extern void tlsprf_init(tlsprf_ctx */*c*/, |
155 | const gcmac */*mcx*/, const gcmac */*mcy*/, |
156 | const void */*k*/, size_t /*ksz*/, |
157 | const void */*sd*/, size_t /*sdsz*/); |
158 | |
159 | /* --- @tlsprf_encrypt@ --- * |
160 | * |
161 | * Arguments: @tlsprf_ctx *c@ = pointer to a context |
162 | * @const void *src@ = pointer to source data |
163 | * @void *dest@ = pointer to destination buffer |
164 | * @size_t sz@ = size of buffer |
165 | * |
166 | * Returns: --- |
167 | * |
168 | * Use: Encrypts data using the TLS pseudo-random function. If the |
169 | * destination pointer is null, the generator is spun and no |
170 | * output is produced; if the source pointer is null, raw output |
171 | * from the generator is written; otherwise, the source data is |
172 | * XORed with the generator output. |
173 | */ |
174 | |
175 | extern void tlsprf_encrypt(tlsprf_ctx */*c*/, |
176 | const void */*src*/, void */*dest*/, |
177 | size_t /*sz*/); |
178 | |
179 | /* --- @tlsprf_free@ --- * |
180 | * |
181 | * Arguments: @tlsprf_ctx *c@ = pointer to a context |
182 | * |
183 | * Returns: --- |
184 | * |
185 | * Use: Frees a TLS PRF context. |
186 | */ |
187 | |
188 | extern void tlsprf_free(tlsprf_ctx */*c*/); |
189 | |
190 | /* ---@tlsprf_rand@ --- * |
191 | * |
192 | * Arguments: @const gcmac *mcx, *mcy@ = MAC function to use |
193 | * @const void *k@ = pointer to the key material |
194 | * @size_t ksz@ = size of the key material |
195 | * @const void *sd@ = pointer to the seed material |
196 | * @size_t sdsz@ = size of the seed material |
197 | * |
198 | * Returns: Pointer to generic random number generator interface. |
199 | * |
200 | * Use: Creates a generic generator which does TLS data expansion. |
201 | */ |
202 | |
203 | extern grand *tlsprf_rand(const gcmac */*mcx*/, const gcmac */*mcy*/, |
204 | const void */*k*/, size_t /*ksz*/, |
205 | const void */*sd*/, size_t /*sdsz*/); |
206 | |
207 | /*----- That's all, folks -------------------------------------------------*/ |
208 | |
209 | #ifdef __cplusplus |
210 | } |
211 | #endif |
212 | |
213 | #endif |