cleanup: Big pile of whitespace fixes, all at once.
[u/mdw/catacomb] / sslprf.h
1 /* -*-c-*-
2 *
3 * $Id: sslprf.h,v 1.2 2004/04/08 01:36:15 mdw Exp $
4 *
5 * The SSL 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_SSLPRF_H
31 #define CATACOMB_SSLPRF_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 sslprf_ctx {
50 const gchash *co, *ci; /* Outer and inner hash functions */
51 size_t ohashsz, ihashsz; /* Size of the hash outputs */
52 ghash *h; /* Hash context from last time */
53 const octet *k; /* Pointer to the secret */
54 size_t ksz; /* Size of the secret buffer */
55 const octet *sd; /* Pointer to the seed */
56 size_t sdsz; /* Size of the seed buffer */
57 unsigned i; /* Which iteration this is */
58 octet *p; /* Pointer to output buffer */
59 size_t sz; /* How many bytes are left */
60 } sslprf_ctx;
61
62 /*----- Functions provided ------------------------------------------------*/
63
64 /* --- @sslprf_init@ --- *
65 *
66 * Arguments: @sslprf_ctx *c@ = pointer to a context structure
67 * @const gchash *hco, *hci@ = outer and inner hash functions
68 * @const void *k@ = pointer to secret buffer
69 * @size_t ksz@ = size of the secret
70 * @const void *sd@ = pointer to seed buffer
71 * @size_t sdsz@ = size of the seed
72 *
73 * Returns: ---
74 *
75 * Use: Initializes an SSL generator context.
76 */
77
78 extern void sslprf_init(sslprf_ctx */*c*/,
79 const gchash */*hco*/, const gchash */*hci*/,
80 const void */*k*/, size_t /*ksz*/,
81 const void */*sd*/, size_t /*sdsz*/);
82
83 /* --- @sslprf_encrypt@ --- *
84 *
85 * Arguments: @sslprf_ctx *c@ = pointer to a context structure
86 * @const void *src@ = pointer to source buffer
87 * @void *dest@ = pointer to destination buffer
88 * @size_t sz@ = size of the buffers
89 *
90 * Returns: ---
91 *
92 * Use: Encrypts data using the SSL pseudo-random 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 sslprf_encrypt(sslprf_ctx */*c*/,
100 const void */*src*/, void */*dest*/,
101 size_t /*sz*/);
102
103 /* --- @sslprf_free@ --- *
104 *
105 * Arguments: @sslprf_ctx@ = pointer to a context
106 *
107 * Returns: ---
108 *
109 * Use: Frees resources held in an SSL generator context.
110 */
111
112 extern void sslprf_free(sslprf_ctx */*c*/);
113
114 /* ---@sslprf_rand@ --- *
115 *
116 * Arguments: @const gchash *hco, const gchash *hci@ = hash functions
117 * @const void *k@ = pointer to the key material
118 * @size_t ksz@ = size of the key material
119 * @const void *sd@ = pointer to the seed material
120 * @size_t sdsz@ = size of the seed material
121 *
122 * Returns: Pointer to generic random number generator interface.
123 *
124 * Use: Creates a generic generator which does TLS data expansion.
125 */
126
127 extern grand *sslprf_rand(const gchash */*hco*/, const gchash */*hci*/,
128 const void */*k*/, size_t /*ksz*/,
129 const void */*sd*/, size_t /*sdsz*/);
130
131 /*----- That's all, folks -------------------------------------------------*/
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif