Example #1
0
static void MakeKey(
	u_char *key,		/* IN  56 bit DES key missing parity bits */
	u_char *des_key		/* OUT 64 bit DES key with parity bits added */
)
{
	des_key[0] = Get7Bits(key,  0);
	des_key[1] = Get7Bits(key,  7);
	des_key[2] = Get7Bits(key, 14);
	des_key[3] = Get7Bits(key, 21);
	des_key[4] = Get7Bits(key, 28);
	des_key[5] = Get7Bits(key, 35);
	des_key[6] = Get7Bits(key, 42);
	des_key[7] = Get7Bits(key, 49);
	
#ifndef USE_CRYPT
	des_set_odd_parity((des_cblock *)des_key);
#endif
	
#if 0
	CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
	       key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
	CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
	       des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
#endif
}
Example #2
0
/*
 * Generate a sequence of random des keys
 * using the random block sequence, fixup
 * parity and skip weak keys.
 */
int
des_new_random_key(des_cblock *key)
{
	int urandom;

 again:
	urandom = open("/dev/urandom", O_RDONLY);

	if (urandom < 0)
		des_random_key(key);
	else {
		if (read(urandom, key,
		    sizeof(des_cblock)) != sizeof(des_cblock)) {
			close(urandom);
			des_random_key(key);
		} else
			close(urandom);
	}

	/* random key must have odd parity and not be weak */
	des_set_odd_parity(key);
	if (des_is_weak_key(key))
		goto again;

	return (0);
}
Example #3
0
/* Make the key */
static void
MakeKey(unsigned char *key, unsigned char *des_key)
{
  des_key[0] = Get7Bits(key, 0);
  des_key[1] = Get7Bits(key, 7);
  des_key[2] = Get7Bits(key, 14);
  des_key[3] = Get7Bits(key, 21);
  des_key[4] = Get7Bits(key, 28);
  des_key[5] = Get7Bits(key, 35);
  des_key[6] = Get7Bits(key, 42);
  des_key[7] = Get7Bits(key, 49);

  des_set_odd_parity((des_cblock *) des_key);
}
Example #4
0
static void mdc2_body(MDC2_CTX *c, const unsigned char *in, unsigned int len)
	{
	register DES_LONG tin0,tin1;
	register DES_LONG ttin0,ttin1;
	DES_LONG d[2],dd[2];
	des_key_schedule k;
	unsigned char *p;
	unsigned int i;

	for (i=0; i<len; i+=8)
		{
		c2l(in,tin0); d[0]=dd[0]=tin0;
		c2l(in,tin1); d[1]=dd[1]=tin1;
		c->h[0]=(c->h[0]&0x9f)|0x40;
		c->hh[0]=(c->hh[0]&0x9f)|0x20;

		des_set_odd_parity(&c->h);
		des_set_key_unchecked(&c->h,k);
		des_encrypt(d,k,1);

		des_set_odd_parity(&c->hh);
		des_set_key_unchecked(&c->hh,k);
		des_encrypt(dd,k,1);

		ttin0=tin0^dd[0];
		ttin1=tin1^dd[1];
		tin0^=d[0];
		tin1^=d[1];

		p=c->h;
		l2c(tin0,p);
		l2c(ttin1,p);
		p=c->hh;
		l2c(ttin0,p);
		l2c(tin1,p);
		}
	}
Example #5
0
static void
des3_random_to_key(struct krb5_key_state *ks, const void *in)
{
	uint8_t *outkey;
	const uint8_t *inkey;
	int subkey;

	for (subkey = 0, outkey = ks->ks_key, inkey = in; subkey < 3;
	     subkey++, outkey += 8, inkey += 7) {
		/*
		 * Expand 56 bits of random data to 64 bits as follows
		 * (in the example, bit number 1 is the MSB of the 56
		 * bits of random data):
		 *
		 * expanded = 
		 *	 1  2  3  4  5  6  7  p
		 *	 9 10 11 12 13 14 15  p
		 *	17 18 19 20 21 22 23  p
		 *	25 26 27 28 29 30 31  p
		 *	33 34 35 36 37 38 39  p
		 *	41 42 43 44 45 46 47  p
		 *	49 50 51 52 53 54 55  p
		 *	56 48 40 32 24 16  8  p
		 */
		outkey[0] = inkey[0];
		outkey[1] = inkey[1];
		outkey[2] = inkey[2];
		outkey[3] = inkey[3];
		outkey[4] = inkey[4];
		outkey[5] = inkey[5];
		outkey[6] = inkey[6];
		outkey[7] = (((inkey[0] & 1) << 1)
		    | ((inkey[1] & 1) << 2)
		    | ((inkey[2] & 1) << 3)
		    | ((inkey[3] & 1) << 4)
		    | ((inkey[4] & 1) << 5)
		    | ((inkey[5] & 1) << 6)
		    | ((inkey[6] & 1) << 7));
		des_set_odd_parity((des_cblock *) outkey);
		if (des_is_weak_key((des_cblock *) outkey))
			outkey[7] ^= 0xf0;
	}

	des3_set_key(ks, ks->ks_key);
}
Example #6
0
void set_user_key(unsigned char *UserKey)
{
    memcpy(cbc_user, UserKey, 8);
    /* Make sure the parity is odd */
    des_set_odd_parity((C_Block *)cbc_user);
}
Example #7
0
bool ServerConf::isEligible(){
	mysqlpp::Connection con = mysqlpp::Connection(false);
	mysqlpp::Query q = NULL;
	mysqlpp::StoreQueryResult qr;

	char *dbKeyBytes;
	char *sharedKey;
	char buffer[25];

	int b64decodedSize;

	char yyyy[5], mm[3], dd[3], fdd[5];

	DES_cblock cb1, cb2, cb3;
	DES_key_schedule ks1, ks2, ks3;

	time_t now = time(0);
	time_t future;

	struct tm expire_time;
	struct tm creation_time;

	memset(buffer, 0x00, 25);
	memset(yyyy, 0x00, 5);
	memset(mm, 0x00, 3);
	memset(dd, 0x00, 3);
	memset(fdd, 0x00, 5);

	memset(&expire_time, 0x00, sizeof(struct tm));

	if( con.connect(mysql_sentry_dbname, mysql_sentry_ip, mysql_sentry_user, mysql_sentry_password, 3306) ){
		q = con.query("SELECT activationkey FROM commonconfiguration");
		//q = con.query("select 'et6hyYTfpfhqZqlPP6WRJRjI09MNuOSJ' as 'activationkey'");
		qr = q.store();
		if(qr.size() == 0){
			std::cerr << "Key info not found" << std::endl;
		}else{
			std::cout << "Base64 Encoded data is " << (*qr.data())[0] << std::endl;

			Base64Decode((char *)((*qr.data())[0]).c_str(), &dbKeyBytes, &b64decodedSize);

			if(b64decodedSize < 0x0A)
				std::cerr << "Invalid Key" << std::endl;
			else{
				sharedKey = getKey();



				memcpy((DES_cblock *)cb1, sharedKey,8);
				memcpy((DES_cblock *)cb2, sharedKey+8,8);
				memcpy((DES_cblock *)cb3, sharedKey+16,8);

				/*DES_set_key(&cb1,&ks1);
				DES_set_key(&cb2,&ks2);
				DES_set_key(&cb3,&ks3);*/

				des_set_odd_parity(&cb1);
				des_set_odd_parity(&cb2);
				des_set_odd_parity(&cb3);


				if(DES_set_key_checked(&cb1, &ks1) || DES_set_key_checked(&cb2, &ks2) || DES_set_key_checked(&cb3, &ks3) ){
					std::cerr << "3DES key scheduling error" << std::endl;
				}else{

					DES_ecb3_encrypt((C_Block *)dbKeyBytes,(C_Block *)buffer, &ks1, &ks2, &ks3, DES_DECRYPT);
					DES_ecb3_encrypt((C_Block *)dbKeyBytes+1,(C_Block *)buffer+1, &ks1, &ks2, &ks3, DES_DECRYPT);
					DES_ecb3_encrypt((C_Block *)dbKeyBytes+2,(C_Block *)buffer+2, &ks1, &ks2, &ks3, DES_DECRYPT);

					free(sharedKey);
					free(dbKeyBytes);

					//std::cout << "Buffer " << buffer << std::endl;

					strncpy(yyyy, buffer+8, 4);
					strncpy(mm, buffer+12, 2);
					strncpy(dd, buffer+14, 2);
					strncpy(fdd, buffer+16, 4);

					expire_time.tm_mday = atoi(dd);
					expire_time.tm_mon = atoi(mm)-1;
					expire_time.tm_year = atoi(yyyy) - 1900;

					creation_time = expire_time;

					expire_time.tm_mday +=   atoi(fdd);

					future = mktime(&creation_time);

					if(now > future)
					{
						future = mktime(&expire_time);

						if(future >= now)
							return true;
					}

				}
			}
		}
	}else{
		std::cerr << "Unable to check eligibility, Connection failed..." << std::endl;
	}

	if(con.connected())
		con.disconnect();

	return false;

}