]> git.cryptolib.org Git - avr-crypto-lib.git/blob - arcfour/arcfour.h
d7bb60632c3e1a3db599dfb76074de6183da8b74
[avr-crypto-lib.git] / arcfour / arcfour.h
1 /* arcfour.h */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  * File:        arcfour.h
21  * Author:      Daniel Otte
22  * Date:        2006-06-07
23  * License: GPLv3+
24  * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
25  */
26
27 /**
28  * \file        arcfour.h
29  * \author      Daniel Otte
30  * \date        2006-06-07
31  * \license GPLv3+
32  * \brief Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
33  *
34  * This header file defines the interface of the ARCFOUR cipher implementation.
35  *
36  * This implementation aims to be compatible with the ARCFOUR description
37  * available at
38  * http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt
39  */
40
41
42 #ifndef ARCFOUR_H_
43 #define ARCFOUR_H_
44
45 #include <stdint.h>
46
47 /** \typedef arcfour_ctx_t
48  * \brief type for arcfour context
49  *
50  * A variable of this type may contain a complete ARCFOUR context.
51  * The context is used to store the state of the cipher and gets
52  * created by the arcfour_init(arcfour_ctx_t *c, uint8_t *key, uint8_t length_B)
53  * function. The context is of the fixed size of 258 bytes
54  */
55
56 /** \struct arcfour_ctx_st
57  * \brief base for ::arcfour_ctx_t
58  *
59  * The struct holds the two indices and the S-Box
60  */
61 typedef struct arcfour_ctx_st {
62         uint8_t i,j;
63         uint8_t s[256];
64 } arcfour_ctx_t;
65
66
67 /** \fn void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx)
68  * \brief setup a context with a key
69  *
70  * This function sets up a ::arcfour_ctx_t context using
71  * the supplied key of the given length.
72  * \param ctx pointer to the context
73  * \param key pointer to the key
74  * \param length_b length of the key in bits (between 8 and 2048)
75  */
76
77 void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx);
78
79 /** \fn uint8_t arcfour_gen(arcfour_ctx_t *ctx)
80  * \brief generates a byte of keystream
81  *
82  * This function generates the next byte of keystream
83  * from the supplied ::arcfour_ctx_t context which is updated accordingly
84  *
85  * \param ctx pointer to the context
86  * \return byte of keystream
87  */
88
89 uint8_t arcfour_gen(arcfour_ctx_t *ctx);
90
91 #endif