chiark / gitweb /
Add support for SSL pseudo-random function.
[catacomb] / sslprf.h
1 /* -*-c-*-
2  *
3  * $Id: sslprf.h,v 1.1 2001/04/06 22:05:10 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 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: sslprf.h,v $
33  * Revision 1.1  2001/04/06 22:05:10  mdw
34  * Add support for SSL pseudo-random function.
35  *
36  */
37
38 #ifndef CATACOMB_SSLPRF_H
39 #define CATACOMB_SSLPRF_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 sslprf_ctx {
58   const gchash *co, *ci;                /* Outer and inner hash functions */
59   size_t ohashsz, ihashsz;              /* Size of the hash outputs */
60   ghash *h;                             /* Hash context from last time */
61   const octet *k;                       /* Pointer to the secret */
62   size_t ksz;                           /* Size of the secret buffer */
63   const octet *sd;                      /* Pointer to the seed */
64   size_t sdsz;                          /* Size of the seed buffer */
65   unsigned i;                           /* Which iteration this is */
66   octet *p;                             /* Pointer to output buffer */
67   size_t sz;                            /* How many bytes are left */
68 } sslprf_ctx;
69
70 /*----- Functions provided ------------------------------------------------*/
71
72 /* --- @sslprf_init@ --- *
73  *
74  * Arguments:   @sslprf_ctx *c@ = pointer to a context structure
75  *              @const gchash *hco, *hci@ = outer and inner hash functions
76  *              @const void *k@ = pointer to secret buffer
77  *              @size_t ksz@ = size of the secret
78  *              @const void *sd@ = pointer to seed buffer
79  *              @size_t sdsz@ = size of the seed
80  *
81  * Returns:     ---
82  *
83  * Use:         Initializes an SSL generator context.
84  */
85
86 extern void sslprf_init(sslprf_ctx */*c*/,
87                         const gchash */*hco*/, const gchash */*hci*/,
88                         const void */*k*/, size_t /*ksz*/,
89                         const void */*sd*/, size_t /*sdsz*/);
90
91 /* --- @sslprf_encrypt@ --- *
92  *
93  * Arguments:   @sslprf_ctx *c@ = pointer to a context structure
94  *              @const void *src@ = pointer to source buffer
95  *              @void *dest@ = pointer to destination buffer
96  *              @size_t sz@ = size of the buffers
97  *
98  * Returns:     ---
99  *
100  * Use:         Encrypts data using the SSL pseudo-random 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 sslprf_encrypt(sslprf_ctx */*c*/,
108                            const void */*src*/, void */*dest*/,
109                            size_t /*sz*/);
110
111 /* --- @sslprf_free@ --- *
112  *
113  * Arguments:   @sslprf_ctx@ = pointer to a context
114  *
115  * Returns:     ---
116  *
117  * Use:         Frees resources held in an SSL generator context.
118  */
119
120 extern void sslprf_free(sslprf_ctx */*c*/);
121
122 /* ---@sslprf_rand@ --- *
123  *
124  * Arguments:   @const gchash *hco, const gchash *hci@ = hash functions
125  *              @const void *k@ = pointer to the key material
126  *              @size_t ksz@ = size of the key material
127  *              @const void *sd@ = pointer to the seed material
128  *              @size_t sdsz@ = size of the seed material
129  *
130  * Returns:     Pointer to generic random number generator interface.
131  *
132  * Use:         Creates a generic generator which does TLS data expansion.
133  */
134
135 extern grand *sslprf_rand(const gchash */*hco*/, const gchash */*hci*/,
136                           const void */*k*/, size_t /*ksz*/,
137                           const void */*sd*/, size_t /*sdsz*/);
138
139 /*----- That's all, folks -------------------------------------------------*/
140
141 #ifdef __cplusplus
142   }
143 #endif
144
145 #endif