]> git.cryptolib.org Git - avr-crypto-lib.git/blob - streamcipher_descriptor.h
adjusting make-system for AEAD-Ciphers
[avr-crypto-lib.git] / streamcipher_descriptor.h
1 /* streamcipher_descriptor.h */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2011  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                stremcipher_descriptor.h
21  * \author              Daniel Otte 
22  * \date                2011-01-15
23  * 
24  * \license         GPLv3 or later
25  * 
26  */
27
28 #ifndef STREAMCIPHER_DESCRIPTOR_H_
29 #define STREAMCIPHER_DESCRIPTOR_H_
30 #include <stdint.h>
31 #include <avr/pgmspace.h>
32
33
34 #ifndef VOID_FPT
35 #define VOID_FPT
36 typedef void(*void_fpt)(void);
37 #endif
38
39 typedef void(*sc_init1_fpt)(const void*, void*); /* key of fixed length, no IV*/
40 typedef void(*sc_init2_fpt)(const void*, const void*, void*); /* key and IV of fixed length */
41 typedef void(*sc_init3_fpt)(const void*, uint16_t,void*); /* key of variable length, no IV */
42 typedef void(*sc_init4_fpt)(const void*, uint16_t,const void*, void*); /* key of variable length, IV of fixed length */
43 typedef void(*sc_init5_fpt)(const void*, uint16_t,const void*, uint16_t, void*); /* key and IV of variable length */
44
45 typedef uint8_t(*sc_gen1_fpt)(void*); /* return keystream data */
46 typedef void(*sc_gen2_fpt)(void*, void*); /* write keystream data to buffer */
47
48 typedef uint8_t(*sc_genra1_fpt)(void*, uint64_t); /* return keystream data */
49 typedef void(*sc_genra2_fpt)(void*, void*, uint64_t); /* write keystream data to buffer */
50
51
52 typedef void(*sc_free_fpt)(void*);
53
54 typedef union{
55         void_fpt  initvoid;
56         sc_init1_fpt init1;
57         sc_init2_fpt init2;
58         sc_init3_fpt init3;
59         sc_init4_fpt init4;
60         sc_init5_fpt init5;
61 } sc_init_fpt;
62
63 typedef union{
64         void_fpt    genvoid;
65         sc_gen1_fpt gen1;
66         sc_gen2_fpt gen2;
67 } sc_gen_fpt;
68
69 typedef union{
70         void_fpt      genravoid;
71         sc_genra1_fpt genra1;
72         sc_genra2_fpt genra2;
73 } sc_genra_fpt;
74
75 #define SC_INIT_TYPE   0x07
76 #define SC_INIT_TYPE_1 0x00 /* key of fixed length, no IV*/
77 #define SC_INIT_TYPE_2 0x02 /* key and IV of fixed length */
78 #define SC_INIT_TYPE_3 0x03 /* key of variable length, no IV */
79 #define SC_INIT_TYPE_4 0x04 /* key of variable length, IV of fixed length */
80 #define SC_INIT_TYPE_5 0x05 /* key and IV of variable length */
81
82 #define SC_GEN_TYPE    0x08
83 #define SC_GEN_TYPE_1  0x00 /* return data stream byte */
84 #define SC_GEN_TYPE_2  0x08 /* write data stream block into buffer */
85
86 #define SCDESC_TYPE_STREAMCIPHER 0x03
87
88 typedef struct {
89         uint8_t      type; /* 3 == streamcipher */
90         uint8_t      flags;
91         PGM_P        name;
92         size_t       ctxsize_B;
93         uint16_t     gensize_b;
94         sc_init_fpt  init;
95         sc_gen_fpt   gen;
96         sc_genra_fpt genra;
97         sc_free_fpt  free;
98         PGM_VOID_P   valid_keysize_desc;
99         PGM_VOID_P   valid_ivsize_desc;
100 } scdesc_t; /* streamcipher descriptor type */
101
102 typedef struct{
103         const scdesc_t *desc_ptr;
104         size_t          keysize;
105         size_t          ivsize;
106         uint16_t        index;
107         uint8_t*        buffer;
108         void*           ctx;
109 } scgen_ctx_t;
110
111 #endif /* STREAMCIPHER_DESCRIPTOR_H_ */
112