-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetkey.h
89 lines (70 loc) · 2.87 KB
/
getkey.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef __getkey_h__
#define __getkey_h__
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "lfsr.h"
// Note: Cheat a bit - KEYBUF and KEYBUF_3 must be the same except for the key size
typedef struct keybuf_struct_t {
int idx; /* index into k */
int bit; /* bit mask [0..7] */
int keyMax; /* RMDsize*2/8 */
int usedBits; /* no used bits */
unsigned char k[RMDsize*2/8]; /* key bits */
} KEYBUF, *KEYBUF_PTR;
// Note: KEYBUF_128_SIZE must be multiple of AES_BLOCK_SIZE
#define KEYBUF_128_SIZE 128
typedef struct keybuf_128_struct_t {
int idx; /* index into k */
int bit; /* bit mask [0..7] */
int keyMax; /* KEYBUF_128_SIZE */
int usedBits; /* no used bits */
unsigned char k[KEYBUF_128_SIZE]; /* key bits */
} KEYBUF_128;
#define KEYBUF_3_MAX_KEY_GROUPS 4
typedef struct keybuf_3_struct_t {
int key_idx; /* [0,1,2,...n] depending on which KEYBUF is current */
int bits_used; /* total bits used */
int max_key_groups; /* KEYBUF_3_MAX_KEY_GROUPS */
KEYBUF key_one; /* a KEYBUF */
KEYBUF key_two; /* "" */
KEYBUF key_three; /* "" */
KEYBUF_128 key_four; /* "" */
} KEYBUF_3, *KEYBUF_3_PTR;
/* iterate through a keybuf_3 */
typedef struct keybuf_3_iterator_t {
/* ptr to keybuf_3 */
KEYBUF_3 *kb;
/* which keybuf */
int key_idx; /* [0,1,2] depending on which KEYBUF is current */
int bits_used; /* total bits used */
/* for current keybuf */
int idx; /* index into k */
int bit; /* bit mask [0..7] */
} KEYBUF_3_ITERATOR, *KEYBUF_3_ITERATOR_PTR;
struct pgm_ctx_struct_t;
/*
* get key bits from 's' of the form:
* "str1,str2,str3,str4,str5,str6"
*/
void getkey_3 ( struct pgm_ctx_struct_t *pgm_ctx, char *s , KEYBUF_3_PTR kp3 );
/* get n key bits 3 */
struct pgm_ctx_struct_t;
aDat getNKeyBits_3 ( struct pgm_ctx_struct_t *pgm_ctx, int n, KEYBUF_3 *kp3 );
/* show bits_used */
void show_bits_used ( KEYBUF_3_PTR kp_3 );
/* XOR the key with itself to use all
* key bits.
*
* n - unused bits to use up
*/
void xor_key_bits ( int n, KEYBUF_3_PTR kp );
/*
* key iterator
*/
/* initialize new iterator */
void kb_iterator_new ( KEYBUF_3_ITERATOR_PTR ki,
KEYBUF_3_PTR kb );
/* get 'n' bits from key interator 'ki' */
aDat getNKeyBits_3_iterator ( struct pgm_ctx_struct_t *pgm_ctx, int n, KEYBUF_3_ITERATOR_PTR ki );
#endif /* __getkey_h__ */