-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsec_init.c
124 lines (102 loc) · 4.43 KB
/
sec_init.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
/*
===========================================================================
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 "qcommon.h"
#define LTM_DESC
#include "sec_common.h"
#include "sec_crypto.h"
#include "tomcrypt/tomcrypt.h"
qboolean initialized = qfalse;
qboolean Sec_Initialized(){
return initialized;
}
void Sec_Init(void)
{
int result,i;
// Connect the math library with the crypt library
ltc_mp = ltm_desc;
//Cmd_AddCommand("createCert", Sec_MakeCert_f);
sec_hashes[SEC_HASH_SHA1].name="SHA1";
sec_hashes[SEC_HASH_SHA1].ID=SEC_HASH_SHA1;
sec_hashes[SEC_HASH_SHA1].hashsize=20;
sec_hashes[SEC_HASH_SHA1].blocksize=64;
sec_hashes[SEC_HASH_SHA1].OID[0]=1;
sec_hashes[SEC_HASH_SHA1].OID[1]=3;
sec_hashes[SEC_HASH_SHA1].OID[2]=14;
sec_hashes[SEC_HASH_SHA1].OID[3]=3;
sec_hashes[SEC_HASH_SHA1].OID[4]=2;
sec_hashes[SEC_HASH_SHA1].OID[5]=26;
sec_hashes[SEC_HASH_SHA1].OIDlen=6;
sec_hashes[SEC_HASH_SHA1].init=&sha1_init;
sec_hashes[SEC_HASH_SHA1].process=&sha1_process;
sec_hashes[SEC_HASH_SHA1].done=&sha1_done;
sec_hashes[SEC_HASH_SHA1].test=&sha1_test;
sec_hashes[SEC_HASH_SHA1].hmac_block=NULL;
/* ------------------------------------------------------------ */
sec_hashes[SEC_HASH_SHA256].name="SHA256";
sec_hashes[SEC_HASH_SHA256].ID=SEC_HASH_SHA256;
sec_hashes[SEC_HASH_SHA256].hashsize=32;
sec_hashes[SEC_HASH_SHA256].blocksize=64;
sec_hashes[SEC_HASH_SHA256].OID[0]=2;
sec_hashes[SEC_HASH_SHA256].OID[1]=16;
sec_hashes[SEC_HASH_SHA256].OID[2]=840;
sec_hashes[SEC_HASH_SHA256].OID[3]=1;
sec_hashes[SEC_HASH_SHA256].OID[4]=101;
sec_hashes[SEC_HASH_SHA256].OID[5]=3;
sec_hashes[SEC_HASH_SHA256].OID[6]=4;
sec_hashes[SEC_HASH_SHA256].OID[7]=2;
sec_hashes[SEC_HASH_SHA256].OID[8]=1;
sec_hashes[SEC_HASH_SHA256].OIDlen=9;
sec_hashes[SEC_HASH_SHA256].init=&sha256_init;
sec_hashes[SEC_HASH_SHA256].process=&sha256_process;
sec_hashes[SEC_HASH_SHA256].done=&sha256_done;
sec_hashes[SEC_HASH_SHA256].test=&sha256_test;
sec_hashes[SEC_HASH_SHA256].hmac_block=NULL;
/* ------------------------------------------------------------ */
sec_hashes[SEC_HASH_TIGER].name="tiger";
sec_hashes[SEC_HASH_TIGER].ID=SEC_HASH_TIGER;
sec_hashes[SEC_HASH_TIGER].hashsize=24;
sec_hashes[SEC_HASH_TIGER].blocksize=64;
sec_hashes[SEC_HASH_TIGER].OID[0]=1;
sec_hashes[SEC_HASH_TIGER].OID[1]=3;
sec_hashes[SEC_HASH_TIGER].OID[2]=6;
sec_hashes[SEC_HASH_TIGER].OID[3]=1;
sec_hashes[SEC_HASH_TIGER].OID[4]=4;
sec_hashes[SEC_HASH_TIGER].OID[5]=1;
sec_hashes[SEC_HASH_TIGER].OID[6]=11591;
sec_hashes[SEC_HASH_TIGER].OID[7]=12;
sec_hashes[SEC_HASH_TIGER].OID[8]=2;
sec_hashes[SEC_HASH_TIGER].OIDlen=9;
sec_hashes[SEC_HASH_TIGER].init=&tiger_init;
sec_hashes[SEC_HASH_TIGER].process=&tiger_process;
sec_hashes[SEC_HASH_TIGER].done=&tiger_done;
sec_hashes[SEC_HASH_TIGER].test=&tiger_test;
sec_hashes[SEC_HASH_TIGER].hmac_block=NULL;
SecCryptErr = CRYPT_OK;
Com_Printf("--- Crypto Initializing ---\n");
for(i = 0;i<SEC_HASH_SIZE__;++i){
result = sec_hashes[i].test();
Com_Printf("Testing %s hash function - %s.\n",sec_hashes[i].name,result==CRYPT_OK ? "positive" : "negative");
if(result != CRYPT_OK){
Com_Error(ERR_FATAL, "Sec module failed to initialize! Error code: %s. Shutting down...\n", Sec_CryptErrStr(result));
return;
}
}
initialized = qtrue;
Com_Printf("--- Crypto Initialization Complete ---\n");
return;
}