forked from mrmekon/libsimplepgp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet_private.h
executable file
·239 lines (206 loc) · 4.93 KB
/
packet_private.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* packet_private.h
* simplepgp
*
* Created by Trevor Bentley on 11/11/11.
*
* Copyright 2011 Trevor Bentley
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _PACKET_PRIVATE_H
#include "simplepgp.h"
//#include "gcrypt.h"
//#include <stdio.h>
#include <setjmp.h>
#include <pthread.h>
/**********************************************************************
**
** MACROS
**
***********************************************************************/
#pragma mark Macros
#define RAISE(err) do { \
pthread_mutex_lock(&spgp_mtx); \
_spgp_err = (err); \
Serial.printf("raise 0x%X\n",_spgp_err); \
pthread_mutex_unlock(&spgp_mtx); \
longjmp(exception,_spgp_err); \
} while(0)
#define SAFE_IDX_INCREMENT(idx,max) \
do{ \
if (++(idx)>=(max)) {\
RAISE(BUFFER_OVERFLOW);\
} \
} while(0)
#define Serial.printf(fmt, ...) do {\
if (debug_log_enabled) {\
Serial.printf("SPGP [%s():%d]: " fmt, \
__FUNCTION__, __LINE__, ## __VA_ARGS__);\
} } while(0)
extern pthread_mutex_t spgp_mtx;
extern uint8_t debug_log_enabled;
extern uint32_t _spgp_err;
extern jmp_buf exception;
struct spgp_packet_header_struct {
spgp_packet_t *parent;
uint32_t contentLength;
uint8_t rawTagByte;
uint8_t isNewFormat;
uint8_t type;
uint8_t headerLength;
uint8_t isPartial;
};
struct spgp_packet_struct {
spgp_pkt_header_t *header;
union {
spgp_public_pkt_t *pub;
spgp_secret_pkt_t *secret;
spgp_userid_pkt_t *userid;
spgp_session_pkt_t *session;
spgp_literal_pkt_t *literal;
spgp_signature_pkt_t *signature;
} c;
spgp_packet_t *next;
spgp_packet_t *prev;
};
struct spgp_mpi_struct {
uint8_t *data;
uint32_t bits;
uint32_t count;
spgp_mpi_t *next;
};
struct spgp_literal_packet_struct {
char *filename;
char *data;
uint32_t dataLen;
uint32_t filenameLen;
};
struct spgp_signature_packet_struct {
uint8_t version;
uint8_t type;
uint8_t asymAlgo;
uint8_t hashAlgo;
uint16_t hashedSubLength;
uint16_t unhashedSubLength;
uint16_t hashTest;
spgp_mpi_t *mpiHead;
};
struct spgp_userid_packet_struct {
uint8_t *data;
};
struct spgp_session_packet_struct {
uint8_t keyid[8];
uint8_t version;
uint8_t algo;
uint8_t symAlgo;
uint32_t keylen;
char *key;
spgp_mpi_t *mpi1;
spgp_mpi_t *mpi2;
};
struct spgp_public_packet_struct {
// This is public key stuff
uint8_t version;
uint32_t creationTime;
uint8_t asymAlgo;
spgp_mpi_t *mpiHead;
uint8_t mpiCount;
uint8_t *fingerprint;
} __attribute__((packed));
struct spgp_secret_packet_struct {
// This is public key stuff
spgp_public_pkt_t pub;
// This is secret key stuff
uint8_t isDecrypted;
uint8_t s2kType;
uint8_t s2kEncryption;
uint8_t s2kSpecifier;
uint8_t s2kHashAlgo;
uint8_t *s2kSalt;
uint8_t s2kSaltLength;
uint8_t s2kCount;
uint8_t *encryptedData;
uint32_t encryptedDataLength;
uint8_t *key;
uint32_t keyLength;
uint8_t *iv;
uint8_t ivLength;
} __attribute__((packed));
typedef enum {
GENERIC_ERROR = 0x100,
OUT_OF_MEMORY,
INVALID_HEADER,
FORMAT_UNSUPPORTED,
INVALID_ARGS,
BUFFER_OVERFLOW,
INCOMPLETE_PACKET,
DECRYPT_FAILED,
GCRY_ERROR,
KEYCHAIN_ERROR,
ZLIB_ERROR,
} spgp_error_t;
typedef enum {
PKT_TYPE_SESSION = 1,
PKT_TYPE_SIGNATURE = 2,
PKT_TYPE_SECRET_KEY = 5,
PKT_TYPE_PUBLIC_KEY = 6,
PKT_TYPE_SECRET_SUBKEY = 7,
PKT_TYPE_COMPRESSED_DATA = 8,
PKT_TYPE_LITERAL_DATA = 11,
PKT_TYPE_USER_ID = 13,
PKT_TYPE_PUBLIC_SUBKEY = 14,
PKT_TYPE_SYM_ENC_INT_DATA = 18,
} spgp_pkt_type_t;
typedef enum {
ASYM_ALGO_RSA = 1,
ASYM_ALGO_RSA_ENCRYPT = 2,
ASYM_ALGO_RSA_SIGN = 3,
ASYM_ALGO_ELGAMAL = 16,
ASYM_ALGO_DSA = 17,
} spgp_asym_algo_t;
typedef enum {
SYM_ALGO_PLAINTEXT = 0,
SYM_ALGO_IDEA,
SYM_ALGO_3DES,
SYM_ALGO_CAST5,
SYM_ALGO_BLOWFISH,
SYM_ALGO_AES128,
SYM_ALGO_AES192,
SYM_ALGO_AES256,
SYM_ALGO_TWOFISH,
} spgp_sym_algo_t;
typedef enum {
HASH_ALGO_MD5 = 1,
HASH_ALGO_SHA1,
HASH_ALGO_RIPEMD160,
HASH_ALGO_SHA256,
HASH_ALGO_SHA384,
HASH_ALGO_SHA512,
HASH_ALGO_SHA224,
} spgp_hash_algo_t;
typedef enum {
COMPRESSION_UNCOMPRESSED = 0,
COMPRESSION_ZIP,
COMPRESSION_ZLIB,
COMPRESSION_BZIP2,
} spgp_compression_t;
typedef enum {
S2K_TYPE_SIMPLE = 0,
S2K_TYPE_SALTED,
S2K_TYPE_RESERVED,
S2K_TYPE_ITERATED,
} spgp_s2k_type_t;
#define _PACKET_PRIVATE_H
#endif