]> git.cryptolib.org Git - avr-crypto-lib.git/blob - a51/A5_1.h
e1346332eebbc0fa11728673bf0b43d2968cf7e0
[avr-crypto-lib.git] / a51 / A5_1.h
1 /* A5_1.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:    A5_1.h
21  * Author:  Daniel Otte
22  * Date:    24.06.2006
23  * License: GPL
24  * Description: Implementation of the A5/1 stream cipher algorithm, as used in GSM.
25  * ! Warning, this is weak crypto !
26  * 
27  */
28 #ifndef A5_1_H_
29 #define A5_1_H_
30
31 #include <stdint.h>
32
33 #define R1_LENGTH 19
34 #define R2_LENGTH 22
35 #define R3_LENGTH 23
36 #define R1_CLK 11
37 #define R2_CLK 12
38 #define R3_CLK 13
39
40 /* 3-Bit word parity lookup table (Byte) 
41  * 0: 0
42  * 1: 1
43  * 2: 1
44  * 3: 0
45  * 4: 1
46  * 5: 0
47  * 6: 0
48  * 7: 1
49  * => 1001.0110 = 0x96
50  * 
51  */
52
53 #define PARITY_LOOKUP 0x96
54
55 typedef struct {
56     /* we are wasting one byte here but this allows a much faster implementation */
57     uint8_t r1[3], r2[3], r3[3]; /* the three regs, 19,22,23 bit in length  */
58 } a5_1_ctx_t;
59
60 void a5_1_init(a5_1_ctx_t *c, void *key, uint8_t keylength_b, void *iv,
61         uint8_t ivlength_b);
62 uint8_t a5_1_clock(a5_1_ctx_t *c);
63 uint8_t a5_1_gen(a5_1_ctx_t *c);
64
65 #endif