示例#1
0
static void Password(const char *pass, const char *key) {
	size_t keylen = strlen(key);
	size_t passlen = strlen(pass);
	// Create a new key, which is the XOR of the "key" and the challenge that
	// was received from the server. If the vectors are of unequal length,
	// the end is padded with values from the longest.
	size_t newLength = keylen;
	if (gLoginChallenge.size() > newLength)
		newLength = gLoginChallenge.size();
	unsigned char newkey[newLength];
	for (size_t i=0; i<newLength; i++) newkey[i] = 0;
	for (size_t i=0; i<keylen; i++) newkey[i] = key[i];
	for (size_t i=0; i<gLoginChallenge.size(); i++) newkey[i] ^= gLoginChallenge[i];
#if 0
	printf("Password: Key (len %d): ", newLength);
	for (int i=0; i<newLength; i++) printf("%d ", newkey[i]);
	printf("\n");
#endif
	unsigned char b[passlen+3];
	// Build the message into 'b'.
	b[0] = passlen+3; // LSB of message length
	b[1] = 0;   // MSB of message length
	b[2] = CMD_RESP_PASSWORD;
	memcpy(b+3, pass, passlen); // Initialize with the clear text password
	rc4_init(newkey, newLength);
	rc4_xor(b+3, passlen); // Encrypt the password

#if 0
	printf("encr: ");
	for (int i=0; i<passlen; i++) printf(" %d", b[i+3]);
	printf("\n");
#endif

	SendMsg(b, passlen+3);
}
示例#2
0
void rc4_test() {
    // Test of encryption, according to http://en.wikipedia.org/wiki/RC4#Test_vectors
    unsigned char buff[100];
    strcpy((char *)buff, "Plaintext");
    int l1 = strlen((char *)buff);
    rc4_init((const unsigned char*)"Key", 3);
    rc4_xor(buff, l1);
    printf("rc4_test: ");
    for (int i=0; i<l1; i++)
        printf("%d ", buff[i]);
    printf("\n");
}