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