-
Notifications
You must be signed in to change notification settings - Fork 0
/
sec_common.c
142 lines (111 loc) · 3.71 KB
/
sec_common.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
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
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_shared.h"
#include "tomcrypt/tomcrypt.h"
#include "sec_common.h"
void *Sec_Malloc(size_t size){
void *ptr = malloc(size);
if(ptr == NULL){
printf("ERROR: Sec_Malloc - No memory!\nTerminating...\n");
exit(666); // Because lack of memory is EVIL!
}
return ptr;
}
int SecCryptErr;
char *Sec_CryptErrStr(int code){
switch(code){
case CRYPT_OK: return "CRYPT_OK";
case CRYPT_ERROR: return "CRYPT_ERROR";
case CRYPT_NOP: return "CRYPT_NOP";
case CRYPT_INVALID_KEYSIZE: return "CRYPT_INVALID_KEYSIZE";
case CRYPT_INVALID_ROUNDS: return "CRYPT_INVALID_ROUNDS";
case CRYPT_FAIL_TESTVECTOR: return "CRYPT_FAIL_TESTVECTOR";
case CRYPT_BUFFER_OVERFLOW: return "CRYPT_BUFFER_OVERFLOW";
case CRYPT_INVALID_PACKET: return "CRYPT_INVALID_PACKET";
case CRYPT_INVALID_PRNGSIZE: return "CRYPT_INVALID_PRNGSIZE";
case CRYPT_ERROR_READPRNG: return "CRYPT_ERROR_READPRNG";
case CRYPT_INVALID_CIPHER: return "CRYPT_INVALID_CIPHER";
case CRYPT_INVALID_HASH: return "CRYPT_INVALID_HASH";
case CRYPT_INVALID_PRNG: return "CRYPT_INVALID_PRNG";
case CRYPT_MEM: return "CRYPT_MEM";
case CRYPT_PK_TYPE_MISMATCH: return "CRYPT_PK_TYPE_MISMATCH";
case CRYPT_PK_NOT_PRIVATE: return "CRYPT_PK_NOT_PRIVE";
case CRYPT_INVALID_ARG: return "CRYPT_INVALID_ARG";
case CRYPT_FILE_NOTFOUND: return "CRYPT_FILE_NOTFOUND";
case CRYPT_PK_INVALID_TYPE: return "CRYPT_PK_INVALID_TYPE";
case CRYPT_PK_INVALID_SYSTEM: return "CRYPT_PK_INVALID_SYSTEM";
case CRYPT_PK_DUP: return "CRYPT_PK_DUP";
case CRYPT_PK_NOT_FOUND: return "CRYPT_NO_FOUND";
case CRYPT_PK_INVALID_SIZE: return "CRYPT_INVALID_SIZE";
case CRYPT_INVALID_PRIME_SIZE: return "CRYPT_INVALID_PRIME_SIZE";
case CRYPT_PK_INVALID_PADDING: return "CRYPT_PK_INVALID_PADDING";
default: return "Unknown error";
}
}
/*
================================
Hash descriptors from tomcrypt
================================
*/
volatile const struct ltc_hash_descriptor sec_sha1_desc =
{
"sha1",
2,
20,
64,
/* OID */
{ 1, 3, 14, 3, 2, 26, },
6,
&sha1_init,
&sha1_process,
&sha1_done,
&sha1_test,
NULL
};
volatile const struct ltc_hash_descriptor sec_sha256_desc =
{
"sha256",
0,
32,
64,
/* OID */
{ 2, 16, 840, 1, 101, 3, 4, 2, 1, },
9,
&sha256_init,
&sha256_process,
&sha256_done,
&sha256_test,
NULL
};
volatile const struct ltc_hash_descriptor sec_tiger_desc =
{
"tiger",
1,
24,
64,
/* OID */
{ 1, 3, 6, 1, 4, 1, 11591, 12, 2, },
9,
&tiger_init,
&tiger_process,
&tiger_done,
&tiger_test,
NULL
};
/*
unsigned long sec_test = sec_tiger_desc.hashsize;
unsigned long sec_test2 = tiger_desc.hashsize;*/