3 * $Id: tlsprf.h,v 1.1 2001/04/04 20:10:52 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2001/04/04 20:10:52 mdw
34 * Add support for the TLS pseudo-random function.
38 #ifndef CATACOMB_TLSPRF_H
39 #define CATACOMB_TLSPRF_H
45 /*----- Header files ------------------------------------------------------*/
47 #ifndef CATACOMB_GMAC_H
51 #ifndef CATACOMB_GRAND_H
55 /*----- Data structures ---------------------------------------------------*/
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 */
68 typedef struct tlsprf_ctx
{
72 /*----- The data expansion function ---------------------------------------*/
74 /* --- @tlsdx_init@ --- *
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
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.
88 extern void tlsdx_init(tlsdx_ctx */
*c*/
, gmac */
*m*/
,
89 const void */
*sd*/
, size_t /*sdsz*/);
91 /* --- @tlsdx_encrypt@ --- *
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
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.
107 extern void tlsdx_encrypt(tlsdx_ctx */
*c*/
, const void */
*src*/
,
108 void */
*dest*/
, size_t /*sz*/);
110 /* --- @tlsdx_free@ --- *
112 * Arguments: @tlsdx_ctx *c@ = pointer to the context block
116 * Use: Frees a context for the TLS data expansion function
119 extern void tlsdx_free(tlsdx_ctx */
*c*/
);
121 /* ---@tlsdx_rand@ --- *
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
129 * Returns: Pointer to generic random number generator interface.
131 * Use: Creates a generic generator which does TLS data expansion.
134 extern grand
*tlsdx_rand(const gcmac */
*mc*/
,
135 const void */
*k*/
, size_t /*ksz*/,
136 const void */
*sd*/
, size_t /*sdsz*/);
138 /* --- The actual very paranoid PRF ---------------------------------------*/
140 /* --- @tlsprf_init@ --- *
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
151 * Use: Initializes a TLS PRF context.
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*/);
159 /* --- @tlsprf_encrypt@ --- *
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
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.
175 extern void tlsprf_encrypt(tlsprf_ctx */
*c*/
,
176 const void */
*src*/
, void */
*dest*/
,
179 /* --- @tlsprf_free@ --- *
181 * Arguments: @tlsprf_ctx *c@ = pointer to a context
185 * Use: Frees a TLS PRF context.
188 extern void tlsprf_free(tlsprf_ctx */
*c*/
);
190 /* ---@tlsprf_rand@ --- *
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
198 * Returns: Pointer to generic random number generator interface.
200 * Use: Creates a generic generator which does TLS data expansion.
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*/);
207 /*----- That's all, folks -------------------------------------------------*/