Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 193177 | Differences between
and this patch

Collapse All | Expand All

(-)a/DH1080.c (-76 / +33 lines)
Lines 13-23 to base64 for final use with blowfish. * Link Here
13
13
14
#include <stdio.h>
14
#include <stdio.h>
15
#include <time.h>
15
#include <time.h>
16
#include <string.h>
16
#include "DH1080.h"
17
#include "DH1080.h"
17
18
18
// ### new sophie-germain 1080bit prime number ###
19
// ### new sophie-germain 1080bit prime number ###
19
char *prime1080="++ECLiPSE+is+proud+to+present+latest+FiSH+release+featuring+even+more+security+for+you+++shouts+go+out+to+TMG+for+helping+to+generate+this+cool+sophie+germain+prime+number++++/C32L";
20
//char *prime1080="++ECLiPSE+is+proud+to+present+latest+FiSH+release+featuring+even+more+security+for+you+++shouts+go+out+to+TMG+for+helping+to+generate+this+cool+sophie+germain+prime+number++++/C32L";
20
// Base16: FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B
21
char *prime1080 = "FBE1022E23D213E8ACFA9AE8B9DFADA3EA6B7AC7A7B7E95AB5EB2DF858921FEADE95E6AC7BE7DE6ADBAB8A783E7AF7A7FA6A2B7BEB1E72EAE2B72F9FA2BFB2A2EFBEFAC868BADB3E828FA8BADFADA3E4CC1BE7E8AFE85E9698A783EB68FA07A77AB6AD7BEB618ACF9CA2897EB28A6189EFA07AB99A8A7FA9AE299EFA7BA66DEAFEFBEFBF0B7D8B";
21
// Base10: 12745216229761186769575009943944198619149164746831579719941140425076456621824834322853258804883232842877311723249782818608677050956745409379781245497526069657222703636504651898833151008222772087491045206203033063108075098874712912417029101508315117935752962862335062591404043092163187352352197487303798807791605274487594646923
22
// Base10: 12745216229761186769575009943944198619149164746831579719941140425076456621824834322853258804883232842877311723249782818608677050956745409379781245497526069657222703636504651898833151008222772087491045206203033063108075098874712912417029101508315117935752962862335062591404043092163187352352197487303798807791605274487594646923
22
23
23
24
Lines 27-104 char *prime1080="++ECLiPSE+is+proud+to+p Link Here
27
//         pub_key  = Your public key
28
//         pub_key  = Your public key
28
int DH1080_gen(char *priv_key, char *pub_key)
29
int DH1080_gen(char *priv_key, char *pub_key)
29
{
30
{
30
	unsigned char raw_buf[160], iniHash[33];
31
	unsigned char raw_buf[160];
31
	unsigned long seed;
32
	unsigned long seed;
32
	int len;
33
	int len;
33
34
34
	big b_privkey, b_prime, b_pubkey;
35
	mpz_t mpz_privkey, mpz_prime, mpz_pubkey, mpz_base;
35
	csprng myRNG;
36
	gmp_randstate_t randstate;
36
	miracl *mip;
37
38
	FILE *hRnd;
39
37
40
	priv_key[0]='0';
38
	priv_key[0]='0';
41
	priv_key[1]='\0';
39
	priv_key[1]='\0';
42
	pub_key[0]='0';
40
	pub_key[0]='0';
43
	pub_key[1]='\0';
41
	pub_key[1]='\0';
44
	hRnd = fopen("/dev/urandom", "r");	// don't use /dev/random, it's a blocking device
45
	if(!hRnd) return 0;
46
42
47
	initb64();
43
	initb64();
48
	mip=mirsys(500, 16);
49
44
50
	b_privkey=mirvar(0);
45
	mpz_init(mpz_privkey);
51
	b_pubkey=mirvar(0);
46
	mpz_init(mpz_pubkey);
52
	b_prime=mirvar(0);
47
	mpz_init_set_ui(mpz_base, 2);
53
48
	mpz_init_set_str(mpz_prime, prime1080, 16);
54
	len=b64toh(prime1080, raw_buf);
55
	bytes_to_big(len, raw_buf, b_prime);
56
49
57
	// #*#*#*#*#* RNG START #*#*#*#*#*
50
	// #*#*#*#*#* RNG START #*#*#*#*#*
58
	time((time_t *)&seed);
51
	time((time_t *)&seed);
59
52
60
	seed ^= (long)hRnd << 16;
53
	gmp_randinit_default(randstate);
61
	if(fread(raw_buf, 1, sizeof(raw_buf), hRnd) < 32)
54
	gmp_randseed_ui(randstate, seed);
62
	{
55
	mpz_urandomb(mpz_privkey, randstate, 1080);
63
		ZeroMemory(raw_buf, sizeof(raw_buf));
56
	gmp_randclear(randstate);
64
		fclose(hRnd);
65
		mirkill(b_privkey);
66
		mirkill(b_pubkey);
67
		mirkill(b_prime);
68
		mirexit();
69
		return 0;
70
	}
71
	fclose(hRnd);
72
73
	sha_file(iniPath, iniHash);
74
	memXOR(raw_buf+128, iniHash, 32);
75
	sha_file((unsigned char *)get_irssi_config(), iniHash);
76
	memXOR(raw_buf+128, iniHash, 32);
77
	ZeroMemory(iniHash, sizeof(iniHash));
78
	// first 128 byte in raw_buf: output from /dev/urandom
79
	// last 32 byte in raw_buf: SHA-256 digest from blow.ini and irssi.conf
80
81
	seed *= (unsigned long)mip;
82
	strong_init(&myRNG, sizeof(raw_buf), raw_buf, (unsigned int)seed);
83
	strong_rng(&myRNG);
84
	strong_bigdig(&myRNG, 1080, 2, b_privkey);
85
	strong_kill(&myRNG);
86
	seed=0;
57
	seed=0;
87
	// #*#*#*#*#* RNG END #*#*#*#*#*
58
	// #*#*#*#*#* RNG END #*#*#*#*#*
88
59
89
	powltr(2, b_privkey, b_prime, b_pubkey);
60
	mpz_powm(mpz_pubkey, mpz_base, mpz_privkey, mpz_prime);
90
61
91
	len=big_to_bytes(sizeof(raw_buf), b_privkey, raw_buf, FALSE);
62
	mpz_export((void*)raw_buf, &len, 1, 1, 1, 0, mpz_privkey);
92
	mirkill(b_privkey);
63
	mpz_clear(mpz_privkey);
93
	htob64(raw_buf, priv_key, len);
64
	htob64(raw_buf, priv_key, len);
94
65
95
	len=big_to_bytes(sizeof(raw_buf), b_pubkey, raw_buf, FALSE);
66
	mpz_export((void*)raw_buf, &len, 1, 1, 1, 0, mpz_pubkey);
96
	htob64(raw_buf, pub_key, len);
67
	htob64(raw_buf, pub_key, len);
97
	ZeroMemory(raw_buf, sizeof(raw_buf));
68
	ZeroMemory(raw_buf, sizeof(raw_buf));
98
69
99
	mirkill(b_pubkey);
70
	mpz_clear(mpz_pubkey);
100
	mirkill(b_prime);
71
	mpz_clear(mpz_prime);
101
	mirexit();
102
72
103
	return 1;
73
	return 1;
104
}
74
}
Lines 113-120 int DH1080_comp(char *MyPrivKey, char *H Link Here
113
{
83
{
114
	int i=0, len;
84
	int i=0, len;
115
	unsigned char SHA256digest[35], base64_tmp[160];
85
	unsigned char SHA256digest[35], base64_tmp[160];
116
	big b_myPrivkey, b_HisPubkey, b_prime, b_theKey;
86
	mpz_t mpz_myPrivkey, mpz_hisPubkey, mpz_prime, mpz_theKey;
117
	miracl *mip;
118
87
119
	// Verify base64 strings
88
	// Verify base64 strings
120
	if((strspn(MyPrivKey, B64ABC) != strlen(MyPrivKey)) || (strspn(HisPubKey, B64ABC) != strlen(HisPubKey)))
89
	if((strspn(MyPrivKey, B64ABC) != strlen(MyPrivKey)) || (strspn(HisPubKey, B64ABC) != strlen(HisPubKey)))
Lines 124-164 int DH1080_comp(char *MyPrivKey, char *H Link Here
124
		return 0;
93
		return 0;
125
	}
94
	}
126
95
127
	mip=mirsys(500, 16);
96
	mpz_init(mpz_myPrivkey);
128
97
	mpz_init(mpz_hisPubkey);
129
	b_myPrivkey=mirvar(0);
98
	mpz_init(mpz_theKey);
130
	b_HisPubkey=mirvar(0);
99
	mpz_init_set_str(mpz_prime, prime1080, 16);
131
	b_theKey=mirvar(0);
132
	b_prime=mirvar(0);
133
134
	len=b64toh(prime1080, base64_tmp);
135
	bytes_to_big(len, base64_tmp, b_prime);
136
100
137
	len=b64toh(MyPrivKey, base64_tmp);
101
	len=b64toh(MyPrivKey, base64_tmp);
138
	bytes_to_big(len, base64_tmp, b_myPrivkey);
102
	mpz_import(mpz_myPrivkey, len, 1, 1, 1, 0, base64_tmp);
139
	memset(MyPrivKey, 0x20, strlen(MyPrivKey));
103
	memset(MyPrivKey, 0x20, strlen(MyPrivKey));
140
104
141
	len=b64toh(HisPubKey, base64_tmp);
105
	len=b64toh(HisPubKey, base64_tmp);
142
	bytes_to_big(len, base64_tmp, b_HisPubkey);
106
	mpz_import(mpz_hisPubkey, len, 1, 1, 1, 0, base64_tmp);
143
107
144
	powmod(b_HisPubkey, b_myPrivkey, b_prime, b_theKey);
108
	mpz_powm(mpz_theKey, mpz_hisPubkey, mpz_myPrivkey, mpz_prime);
145
	mirkill(b_myPrivkey);
109
	mpz_clear(mpz_myPrivkey);
146
110
147
	len=big_to_bytes(sizeof(base64_tmp), b_theKey, base64_tmp, FALSE);
111
	mpz_export((void*)base64_tmp, &len, 1, 1, 1, 0, mpz_theKey);
148
	mirkill(b_theKey);
112
	mpz_clear(mpz_theKey);
149
	SHA256_memory(base64_tmp, len, SHA256digest);
113
	SHA256_memory(base64_tmp, len, SHA256digest);
150
	htob64(SHA256digest, HisPubKey, 32);
114
	htob64(SHA256digest, HisPubKey, 32);
151
	ZeroMemory(base64_tmp, sizeof(base64_tmp));
115
	ZeroMemory(base64_tmp, sizeof(base64_tmp));
152
	ZeroMemory(SHA256digest, sizeof(SHA256digest));
116
	ZeroMemory(SHA256digest, sizeof(SHA256digest));
153
117
154
	mirkill(b_HisPubkey);
118
	mpz_clear(mpz_hisPubkey);
155
	mirkill(b_prime);
119
	mpz_clear(mpz_prime);
156
	mirexit();
157
	return 1;
120
	return 1;
158
}
121
}
159
160
161
162
163
164
(-)a/DH1080.h (-1 / +1 lines)
Lines 1-4 Link Here
1
#include "miracl.h"
1
#include <gmp.h>
2
2
3
3
4
// Input:  priv_key = buffer of 200 bytes
4
// Input:  priv_key = buffer of 200 bytes
(-)a/FiSH.h (-1 / +1 lines)
Lines 29-34 unsigned char iniKey[100], blow_ini[]="/ Link Here
29
unsigned char iniKey[100], blow_ini[]="/blow.ini", iniPath[255], tempPath[255];
29
unsigned char iniKey[100], blow_ini[]="/blow.ini", iniPath[255], tempPath[255];
30
char g_myPrivKey[300], g_myPubKey[300];
30
char g_myPrivKey[300], g_myPubKey[300];
31
31
32
BOOL unsetiniFlag=0, keyx_query_created=0;
32
unsigned short int unsetiniFlag=0, keyx_query_created=0;
33
33
34
char *strfcpy(unsigned char *dest, char *buffer);	// removes leading and trailing blanks from string
34
char *strfcpy(unsigned char *dest, char *buffer);	// removes leading and trailing blanks from string
(-)a/SHA-256.c (+1 lines)
Lines 12-17 Link Here
12
 * */
12
 * */
13
13
14
#include <stdio.h>
14
#include <stdio.h>
15
#include <string.h>
15
16
16
typedef struct {
17
typedef struct {
17
    unsigned int state[8], length, curlen;
18
    unsigned int state[8], length, curlen;
(-)a/base64.c (+1 lines)
Lines 1-3 Link Here
1
#include <string.h>
1
/*
2
/*
2
    Public Base64 conversion tables
3
    Public Base64 conversion tables
3
*/
4
*/
(-)a/blowfish.c (+2 lines)
Lines 1-3 Link Here
1
#include <stdlib.h>
2
#include <string.h>
1
#include "blowfish.h"
3
#include "blowfish.h"
2
4
3
/* #define S(x,i) (bf_S[i][x.w.byte##i]) */
5
/* #define S(x,i) (bf_S[i][x.w.byte##i]) */

Return to bug 193177