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