summaryrefslogtreecommitdiff
path: root/plugins/CryptoPP/src/cpp_misc.cpp
blob: d7905b13b7e9f8a9974f49c624233beec7ae548b (plain)
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
#include "commonheaders.h"

int __cdecl cpp_get_features(HANDLE context)
{
	pCNTX ptr = get_context_on_id(context);
	if (!ptr)
		return 0;
	return ptr->features;
}

int __cdecl cpp_get_error(HANDLE context)
{
	pCNTX ptr = get_context_on_id(context);
	if (!ptr)
		return 0;
	return ptr->error;
}

int __cdecl cpp_get_version(void)
{
	return PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM);
}

BOOL cpp_get_simdata(HANDLE context, pCNTX *ptr, pSIMDATA *p)
{
	if (!ptr)
		return 0;
	*ptr = get_context_on_id(context);
	if (!*ptr || (*ptr)->mode&(MODE_PGP | MODE_GPG | MODE_RSA)) return FALSE;
	*p = (pSIMDATA)cpp_alloc_pdata(*ptr);
	return TRUE;
}

int __cdecl cpp_size_keyx(void)
{
	return(Tiger::DIGESTSIZE + 2);
}

void __cdecl cpp_get_keyx(HANDLE context, uint8_t *key)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return;
	memcpy(key, p->KeyX, Tiger::DIGESTSIZE);
	memcpy(key + Tiger::DIGESTSIZE, &ptr->features, 2);
}

void __cdecl cpp_set_keyx(HANDLE context, uint8_t *key)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return;
	SAFE_FREE(p->PubA);
	SAFE_FREE(p->KeyA);
	mir_free(p->KeyB); p->KeyB = nullptr;
	SAFE_FREE(p->KeyX);
	p->KeyX = (uint8_t*)malloc(Tiger::DIGESTSIZE + 2);
	memcpy(p->KeyX, key, Tiger::DIGESTSIZE);
	memcpy(&ptr->features, key + Tiger::DIGESTSIZE, 2);
}

void __cdecl cpp_get_keyp(HANDLE context, uint8_t *key)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return;
	memcpy(key, p->KeyP, Tiger::DIGESTSIZE);
}

int __cdecl cpp_size_keyp(void)
{
	return(Tiger::DIGESTSIZE);
}

void __cdecl cpp_set_keyp(HANDLE context, uint8_t *key)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return;
	SAFE_FREE(p->KeyP);
	p->KeyP = (uint8_t*)malloc(Tiger::DIGESTSIZE);
	memcpy(p->KeyP, key, Tiger::DIGESTSIZE);
}

int __cdecl cpp_keya(HANDLE context)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return 0;
	return p->KeyA != nullptr;
}

int __cdecl cpp_keyb(HANDLE context)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return 0;
	return p->KeyB != nullptr;
}

int __cdecl cpp_keyx(HANDLE context)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return 0;
	return p->KeyX != nullptr;
}

int __cdecl cpp_keyp(HANDLE context)
{
	pCNTX ptr;
	pSIMDATA p;
	if (!cpp_get_simdata(context, &ptr, &p))
		return 0;
	return p->KeyP != nullptr;
}