-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenssl.patch
239 lines (231 loc) · 5.04 KB
/
openssl.patch
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
--- ./openssl/crypto/aes/asm/aes-armv4.pl 2016-04-14 10:20:37.000000000 +0100
+++ ./openssl/crypto/aes/asm/aes-armv4.pl_diff 2016-04-13 17:17:51.000000000 +0100
@@ -52,6 +52,12 @@
$code=<<___;
#include "arm_arch.h"
+
+#ifdef AES_TRIG
+.extern trigger_set
+.extern trigger_clr
+#endif /* AES_TRIG */
+
.text
.code 32
@@ -169,6 +175,15 @@
AES_encrypt:
sub r3,pc,#8 @ AES_encrypt
stmdb sp!,{r1,r4-r12,lr}
+
+ #ifdef AES_TRIG
+ @@ triggering
+ stmdb sp!,{r0-r12,lr}
+ bl trigger_set
+ ldmia sp!,{r0-r12,lr}
+ @@ triggering
+ #endif /* AES_TRIG */
+
mov $rounds,r0 @ inp
mov $key,r2
sub $tbl,r3,#AES_encrypt-AES_Te @ Te
@@ -257,6 +272,15 @@
strb $t3,[$rounds,#14]
strb $s3,[$rounds,#15]
#endif
+
+ #ifdef AES_TRIG
+ @@ triggering
+ stmdb sp!,{r0-r12,lr}
+ bl trigger_clr
+ ldmia sp!,{r0-r12,lr}
+ @@ triggering
+ #endif /* AES_TRIG */
+
#if __ARM_ARCH__>=5
ldmia sp!,{r4-r12,pc}
#else
@@ -885,6 +909,15 @@
AES_decrypt:
sub r3,pc,#8 @ AES_decrypt
stmdb sp!,{r1,r4-r12,lr}
+
+ #ifdef AES_TRIG
+ @@ triggering
+ stmdb sp!,{r0-r12,lr}
+ bl trigger_set
+ ldmia sp!,{r0-r12,lr}
+ @@ triggering
+ #endif /* AES_TRIG */
+
mov $rounds,r0 @ inp
mov $key,r2
sub $tbl,r3,#AES_decrypt-AES_Td @ Td
@@ -973,6 +1006,15 @@
strb $t3,[$rounds,#14]
strb $s3,[$rounds,#15]
#endif
+
+ #ifdef AES_TRIG
+ @@ triggering
+ stmdb sp!,{r0-r12,lr}
+ bl trigger_clr
+ ldmia sp!,{r0-r12,lr}
+ @@ triggering
+ #endif /* AES_TRIG */
+
#if __ARM_ARCH__>=5
ldmia sp!,{r4-r12,pc}
#else
--- ./openssl/crypto/conf/conf.h 2016-04-14 10:20:37.000000000 +0100
+++ ./openssl/crypto/conf/conf.h_diff 2016-04-13 17:09:29.000000000 +0100
@@ -71,6 +71,14 @@
extern "C" {
#endif
+#ifdef AES_TRIG
+int trigger_map(void);
+int trigger_unmap(void);
+int trigger_setup(void);
+int trigger_set(void);
+int trigger_clr(void);
+#endif /* AES_TRIG */
+
typedef struct {
char *section;
char *name;
--- ./openssl/crypto/conf/conf_lib.c 2016-04-14 10:20:37.000000000 +0100
+++ ./openssl/crypto/conf/conf_lib.c_diff 2016-04-14 10:18:41.000000000 +0100
@@ -64,6 +64,114 @@
#include <openssl/conf_api.h>
#include <openssl/lhash.h>
+#ifdef AES_TRIG
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <fcntl.h>
+
+#define MMAP_OFFSET (0x44C00000)
+#define MMAP_SIZE (0x481AEFFF-MMAP_OFFSET)
+
+#define GPIO0_BASE 0x44E07000
+#define GPIO1_BASE 0x4804C000
+#define GPIO2_BASE 0x481AC000
+
+#define GPIO_SIZE 0x00001FFF
+
+#define GPIO_OE 0x134
+#define GPIO_SET 0x194
+#define GPIO_CLR 0x190
+#define GPIO_DO 0x13C
+
+#define PIN_BIT 3
+
+static uint32_t *trigger_gpioBase;
+static uint8_t trigger_active = 0;
+
+int trigger_map(void){
+
+ // variable for mem file descriptor
+ int memfd;
+
+ // check if we have root permissions to be doing this!
+ if ( getuid() != 0 ) {
+ perror("trigger_initMap : this program requires root permissions to run!");
+ return -1;
+ }
+
+ // open mem mapper
+ memfd = open("/dev/mem", O_RDWR);
+
+ // check if there was a problem
+ if (memfd == -1){
+ perror("initMap : Unabe to open /dev/mem");
+ return -1;
+ }
+
+ // map the GPIO2 physical address as R/W
+ trigger_gpioBase = (uint32_t*)mmap(0, MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, GPIO2_BASE);
+
+ // check for any problems
+ if (trigger_gpioBase == MAP_FAILED){
+ close(memfd);
+ perror("initMap : mmap to gpio base failed");
+ return -1;
+ }
+
+ // set the global map active variable...this is shocking but...meh
+ trigger_active = 1;
+ return 1;
+}
+
+int trigger_unmap(void){
+
+ // check if the memory has been mapped
+ if (trigger_active) {
+ // unmap the memory and clear the global flag
+ munmap(trigger_gpioBase, MMAP_SIZE);
+ trigger_active = 0;
+ return 1;
+
+ } else {
+ // if it's not open...then we just ignore the call
+ return 0;
+ }
+
+}
+
+// setup triggger for output signal
+int trigger_setup(void){
+ uint32_t *gpioOE = NULL;
+ gpioOE = trigger_gpioBase + (GPIO_OE/4);
+ *gpioOE &= ~(1 << PIN_BIT);
+ return 0;
+}
+
+// set the trigger to logic 1
+int trigger_set(void){
+ uint32_t* gpioSET = NULL;
+ gpioSET = trigger_gpioBase + (GPIO_SET/4);
+ *gpioSET = (1 << PIN_BIT);
+ return 0;
+}
+
+// set the trigger to logic 0
+int trigger_clr(void){
+ uint32_t* gpioCLR = NULL;
+ gpioCLR = trigger_gpioBase + (GPIO_CLR/4);
+ *gpioCLR = (1 << PIN_BIT);
+ return 0;
+}
+
+#endif /* AES_TRIG */
+
const char CONF_version[] = "CONF" OPENSSL_VERSION_PTEXT;
static CONF_METHOD *default_CONF_method = NULL;
@@ -229,6 +337,12 @@
{
CONF *ret;
+ #ifdef AES_TRIG
+ // Setup GPIO
+ trigger_map();
+ trigger_setup();
+ #endif /* AES_TRIG */
+
if (meth == NULL)
meth = NCONF_default();
@@ -243,6 +357,12 @@
void NCONF_free(CONF *conf)
{
+
+ #ifdef AES_TRIG
+ // tear down gpio
+ trigger_unmap();
+ #endif /* AES_TRIG */
+
if (conf == NULL)
return;
conf->meth->destroy(conf);