-
Notifications
You must be signed in to change notification settings - Fork 79
/
global.c
70 lines (56 loc) · 1.41 KB
/
global.c
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
/*
20140214
20241207 - reformated using clang-format
Jan Mojzis
Public domain.
The 'global' library is used for global memory
initializition and global memory cleanup.
The 'global' library also has space
for 2 versatile buffers.
*/
#include <unistd.h>
#include "newenv.h"
#include "channel.h"
#include "packet.h"
#include "sshcrypto.h"
#include "purge.h"
#include "trymlock.h"
#include "global.h"
unsigned char global_bspace1[GLOBAL_BSIZE];
unsigned char global_bspace2[GLOBAL_BSIZE];
/*
Initialize memory space.
*/
void global_init(void) {
packet_init();
channel_init();
newenv_init();
sshcrypto_init();
trymlock(global_bspace1, sizeof global_bspace1);
trymlock(global_bspace2, sizeof global_bspace2);
purge(global_bspace1, sizeof global_bspace1);
purge(global_bspace2, sizeof global_bspace2);
}
/*
Remove sentitive data from allocated memory.
*/
void global_purge(void) {
unsigned char stack[4096];
purge(stack, sizeof stack);
packet_purge();
channel_purge();
newenv_purge();
sshcrypto_purge();
purge(global_bspace1, sizeof global_bspace1);
purge(global_bspace2, sizeof global_bspace2);
trymunlock(global_bspace1, sizeof global_bspace1);
trymunlock(global_bspace2, sizeof global_bspace2);
}
/*
Remove sentitive data from allocated memory
and exit with status 'x'.
*/
__attribute__((noreturn)) void global_die(int x) {
global_purge();
_exit(x);
}