Пример #1
0
static void CrackWord(unsigned char word[WORD_LENGTH], int index, int len)
{
	MD_CTX context;
	unsigned char digest[16];
	unsigned int i;

	if (index == 0) {
		// MD5 calculate
		MDInit (&context);
		MDUpdate(&context, word, len);
		MDFinal(digest, &context);
		// MD5 finished

		for (i = 0; i < len; i++)
			printf("%c", word[i]);
		printf(":");
		MDPrint(digest);
		printf("\n");

		if (strncmp(digest, md5_target16, 16) == 0) {
			printf("\nFind!!!\n\n");
			found = 1;
			strncpy(original_word, word, len);
		}

		word_count++;
	} else {
		for (i = 0; i < 62; i++) {
			word[index - 1] = char_set[i];
			CrackWord(word, index - 1, len);
		}
	}
}
Пример #2
0
/* Digests a file and prints the result.
*/
static void MDFile(char *filename)
{
    FILE *file;
    MD_CTX context;
    int len;
    unsigned char buffer[1024], digest[16];

    if ((file = fopen(filename, "rb")) == NULL)
    {
        printf("%s can't be opened\n", filename);
    }
    else 
    {
        MDInit(&context);
        while (len = fread(buffer, 1, 1024, file))
        {
            MDUpdate(&context, buffer, len);
        }
        MDFinal(digest, &context);

        fclose(file);
        printf("MD%d (%s) = ", MD, filename);
        MDPrint(digest);
        printf("\n");
    }

}
Пример #3
0
/* Digests the standard input and prints the result.
*/
static void MDFilter ()
{
	MD_CTX context;
	size_t len = 0;
	unsigned char buffer[128] = {0}, digest[16] = {0};

	printf("Input a word(string) (length < 128): \n");

	MDInit(&context);

	if (fgets(buffer, 128, stdin) != NULL) {
		len = strlen(buffer);
		// erase '\n' at the end of the buffer
		buffer[len - 1] = '\0';
		len --;
		printf("Length: %d\n", len);
	} else
		return;

	MDUpdate(&context, buffer, len);
	MDFinal(digest, &context);

	printf("MD5 (\"%s\") = ", buffer);
	MDPrint(digest);
	printf("\n");
}
Пример #4
0
/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
blocks.
*/
static void MDTimeTrial ()
{
	MD_CTX context;
	struct timeval endTime, startTime;
	double timedif;
	unsigned char block[TEST_BLOCK_LEN], digest[16];
	unsigned int i;
	printf("MD%d time trial. Digesting %d %d-byte blocks ...", MD, TEST_BLOCK_LEN, TEST_BLOCK_COUNT);

	/* Initialize block */
	for (i = 0; i < TEST_BLOCK_LEN; i++)
		block[i] = (unsigned char)(i & 0xff);

	/* Start timer */
	gettimeofday(&startTime, NULL);

	/* Digest blocks */
	MDInit (&context);
	for (i = 0; i < TEST_BLOCK_COUNT; i++)
		MDUpdate(&context, block, TEST_BLOCK_LEN);
	MDFinal(digest, &context);

	/* Stop timer */
	gettimeofday(&endTime, NULL);

	printf(" done\n");
	printf("Digest = ");
	MDPrint(digest);

	timedif = (endTime.tv_sec - startTime.tv_sec) + (endTime.tv_usec - startTime.tv_usec) / 1000000.0;

	printf("\nTime = %f seconds\n", timedif);
	printf("Speed = %f bytes/second\n", (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT / timedif);
}
Пример #5
0
char* MDString (char *string){

  MD5_CTX context;
  static unsigned char digest[64];
  unsigned int len = strlen (string);

  MDInit (&context);
  MDUpdate (&context, string, len);
  MDFinal (digest, &context);

  return digest;
}
Пример #6
0
static void MDWordTimeConvert()
{
	int minLength = 1;
	int maxLength = WORD_LENGTH;
	unsigned char word[WORD_LENGTH];
 
	int word_count = 0;

	struct timeval endTime, startTime;
	double timedif;
	MD_CTX context;
	/* Start timer */
	gettimeofday(&startTime, NULL);

	for (int i = minLength; i <= maxLength; i++) {
		long maxNum = (long)pow(62, i);

#pragma omp parallel for num_threads(2)
		for (long j = 0; j < maxNum; j++) {
			ConvertTo62(word, j, i);

			unsigned char digest[16];
			MDInit (&context);
			MDUpdate(&context, word, i);
			MDFinal(digest, &context);
			/* Print info
			for (int p = 0; p < i; p++)
				printf("%c", word[p]);
			printf(":");
			MDPrint(digest);
			printf("\n");
			*/
#pragma omp critical (section1)
			{
				word_count++;
			}
		}
	}

	/* Stop timer */
	gettimeofday(&endTime, NULL);

	printf(" Word_count: %d\n", word_count);
	printf(" Done\n");

	timedif = (endTime.tv_sec - startTime.tv_sec) + (endTime.tv_usec - startTime.tv_usec) / 1000000.0;
	printf("\n Time = %f seconds\n", timedif);
    printf(" Words per second: %.f\n", word_count / timedif);

	return;
}
Пример #7
0
/* Digests a string and prints the result.
*/
static void MDString(char *string)
{
	MD_CTX context;
	unsigned char digest[16];
	unsigned int len = strlen(string);

	MDInit(&context);
	MDUpdate(&context, string, len);
	MDFinal(digest, &context);

	printf("MD%d (\"%s\") = ", MD, string);
	MDPrint(digest);
	printf("\n");
}
Пример #8
0
/* Digests the standard input and prints the result.
 */
static void MDFilter(void)
{
    MD_CTX context;
    int len;
    unsigned char buffer[16], digest[16];

    MDInit(&context);
    while (len = fread(buffer, 1, 16, stdin))
    {
        MDUpdate(&context, buffer, len);
    }
    MDFinal(digest, &context);

    MDPrint(digest);
    printf("\n");
}
Пример #9
0
/* Digests a string array and store the result in dst; assumes
  32 bytes in dst
 */
void MD5StringArray (char *dst, str src[], int size)
{
	MD_CTX context;
	unsigned char digest[16];
 	int i;
	int len;
	char *s;

/*
#	ifdef EXTRA_DEBUG
	int j;
	int sum;
#endif
*/

	MDInit (&context);
	for (i=0; i<size; i++) {
		trim_len( len, s, src[i] );
/*
#		ifdef EXTRA_DEBUG
		fprintf(stderr, "EXTRA_DEBUG: %d. (%d) {", i+1, len);
		sum=0;
		for (j=0; j<len; j++) {
			fprintf( stderr, "%c ", *(s+j));
			sum+=*(s+j);
		}
		for (j=0; j<len; j++) {
			fprintf( stderr, "%d ", *(s+j));
			sum+=*(s+j);
		}
		fprintf(stderr, " [%d]\n", sum );	
#		endif
*/
		if (len > 0)
  			MDUpdate (&context, s, len);
  }
  MDFinal (digest, &context);

  string2hex(digest, 16, dst );
  DBG("DEBUG: MD5 calculated: %.*s\n", MD5_LEN, dst );

}
Пример #10
0
u_long md_32(char *string, int length) 
{
  MD_CTX context;
  union {
    char   c[16];
    u_long x[4];
  } digest;
  u_long r;
  int i;

  MDInit (&context); 
  MDUpdate (&context, string, length); 
  MDFinal ((unsigned char *)&digest, &context); 
  r = 0; 
  for (i = 0; i < 3; i++) { 
    r ^= digest.x[i]; 
  } 
  return r; 
  
}                               /* md_32 */
Пример #11
0
static int cmppasswds(char *passwd, unsigned char *thepw)
{
  MD_CTX context;
  unsigned char digest[16];
  char newpw[30];
  int i;

  strcpy(newpw, passwd);
  strupr(newpw);

  MDInit(&context);
  MDUpdate(&context, (unsigned char*) newpw, strlen(newpw));
  MDFinal(digest, &context);

  for (i = 0; i < 16; i++) {
    if (thepw[i] != digest[i])
      return (0);
  }
  return (1);
}
Пример #12
0
// MD5 Word Count Time Test
static void CrackWordTime(unsigned char word[WORD_LENGTH], int index, int len)
{
	MD_CTX context;
	unsigned char digest[16];
	unsigned int i;

	if (index == 0) {
		// MD5 calculate
		MDInit (&context);
		MDUpdate(&context, word, len);
		MDFinal(digest, &context);
		// MD5 finished

#pragma omp critical (section1)
		word_count++;
	} else {
#pragma omp parallel for num_threads(2)
		for (i = 0; i < 62; i++) {
			word[index - 1] = char_set[i];
			CrackWordTime(word, index - 1, len);
		}
	}
}
Пример #13
0
/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks. */
static void MDTimeTrial (void)
{
    MD_CTX context;
    time_t endTime, startTime;
    unsigned char block[TEST_BLOCK_LEN], digest[16];
    unsigned int i;

    printf("MD%d time trial. Digesting %d %d-byte blocks ...", MD,TEST_BLOCK_LEN, TEST_BLOCK_COUNT);

    /* Initialize block */
    for (i = 0; i < TEST_BLOCK_LEN; i++)
    {
        block[i] = (unsigned char)(i & 0xff);
    }

    /* Start timer */
    time(&startTime);

    /* Digest blocks */
    MDInit (&context);
    for (i = 0; i < TEST_BLOCK_COUNT; i++)
    {
        MDUpdate (&context, block, TEST_BLOCK_LEN);
    }
    MDFinal (digest, &context);

    /* Stop timer */
    time (&endTime);

    printf(" done\n");
    printf("Digest = ");
    MDPrint(digest);
    printf("\nTime = %ld seconds\n", (long)(endTime-startTime));
    printf("Speed = %ld bytes/second\n",(long)TEST_BLOCK_LEN* (long)TEST_BLOCK_COUNT/(endTime-startTime));

}
Пример #14
0
/* FIXME! buffer overflows? */
static int handle_choice(const char *askbuf)
{
	char lesbabuf[30];
	struct userbase muser = user;
	int leps;
		
	if (!(strcasecmp(askbuf, "1"))) {
		for (;;) {
			if (!isaccess(SECB_REALNAME, access2))
				break;
			DDPut(sd[eu1str]);
			strlcpy(lesbabuf, user.user_realname, sizeof lesbabuf);
			if (!(Prompt(lesbabuf, 25, 0)))
				return 1;
			removespaces(lesbabuf);
			if (strcasecmp(lesbabuf, user.user_realname)) {
				leps = findusername(lesbabuf);
				if (leps == user.user_account_id || leps == -1) {
					if (lesbabuf[0])
						strlcpy(user.user_realname, lesbabuf, sizeof user.user_realname);
				} else {
					DDPut(sd[newalreadystr]);
					continue;
				}
			}
			break;
		}
	} else if (!(strcasecmp(askbuf, "2"))) {
		for (;;) {
			if (!isaccess(SECB_HANDLE, access2))
				break;
			DDPut(sd[eu2str]);
			strlcpy(lesbabuf, user.user_handle, sizeof lesbabuf);
			if (!(Prompt(lesbabuf, 25, 0)))
				return 1;
			removespaces(lesbabuf);
			if (strcasecmp(lesbabuf, user.user_handle)) {
				leps = findusername(lesbabuf);
				if (leps == user.user_account_id || leps == -1) {
					if (lesbabuf[0])
						strlcpy(user.user_handle, lesbabuf, sizeof user.user_handle);
				} else {
					DDPut(sd[newalreadystr]);
					continue;
				}
			}
			break;
		}
	} else if (!(strcasecmp(askbuf, "3"))) {
		DDPut(sd[eu3str]);
		if (!(Prompt(user.user_organization, 25, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "4"))) {
		DDPut(sd[eu4str]);
		if (!(Prompt(user.user_zipcity, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "5"))) {
		DDPut(sd[eu5str]);
		if (!(Prompt(user.user_voicephone, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "6"))) {
		MD_CTX context;
		char verifypw[32];
		DDPut(sd[eu6str]);
		lesbabuf[0] = 0;
		if (!(Prompt(lesbabuf, 15, PROMPT_SECRET)))
			return 1;
		if (lesbabuf[0] == 0)
			return 0;
		*verifypw = 0;
		DDPut(sd[euverifypwstr]);
		if (!(Prompt(verifypw, 15, PROMPT_SECRET)))
			return 1;
		if (strcasecmp(lesbabuf, verifypw)) {
			DDPut(sd[eunomatchstr]);
			return 0;
		}
		strupr(lesbabuf);
		MDInit(&context);
		MDUpdate(&context, (unsigned char *) lesbabuf, 
			strlen(lesbabuf));
		MDFinal(user.user_password, &context);
	} else if (!strcasecmp(askbuf, "7")) {
		for (;;) {
			int fallos;
			
			DDPut(sd[eu7str]);
			lesbabuf[0] = 0;
			if (!(Prompt(lesbabuf, 3, 0)))
				return 1;
			if (lesbabuf[0] == 't' || lesbabuf[0] == 'T') {
				testscreenl();
				continue;
			}
			fallos = atoi(lesbabuf);
			if (fallos < 10) {
				DDPut(sd[newminslstr]);
				continue;
			}
			user.user_screenlength = fallos;
			break;
		}
	} else if (!(strcasecmp(askbuf, "8"))) {
		struct DayDream_Protocol *tp;

		TypeFile("protocols", TYPE_MAKE | TYPE_WARN);
		DDPut(sd[eu8str]);
		*lesbabuf = 0;
		if (user.user_protocol) {
			*lesbabuf = user.user_protocol;
			lesbabuf[1] = 0;
		}
		if (!(Prompt(lesbabuf, 3, 0)))
			return 1;
		*lesbabuf = toupper(*lesbabuf);
		if (!*lesbabuf)
			return 0;
		tp = protocols;
		for (;;) {
			if (tp->PROTOCOL_ID == 0)
				return 0;
			if (tp->PROTOCOL_ID == *lesbabuf) {
				protocol = tp;
				user.user_protocol = *lesbabuf;
				return 0;
			}
			tp++;
		}
	} else if (!(strcasecmp(askbuf, "9"))) {
		DDPut(sd[eu9str]);
		if (!(Prompt(user.user_signature, 44, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "10"))) {
		DDPut(sd[eu10str]);
		if (!(Prompt(user.user_computermodel, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "11"))) {
		DDPut(sd[eu11str]);
		snprintf(lesbabuf, sizeof lesbabuf, "%d", user.user_flines);
		if (!(Prompt(lesbabuf, 3, 0)))
			return 1;
		user.user_flines = atoi(lesbabuf);
        } else if (!(strcasecmp(askbuf, "12"))) {
		rundoor("doors/autosig %N", 0);
		return 1;
	} else if (!(strcasecmp(askbuf, "a"))) {
		DDPut(sd[euabortedstr]);
		user = muser;
		return 1;
	} else if (!(strcasecmp(askbuf, "v"))) {
		TypeFile("edituser", TYPE_MAKE | TYPE_WARN);
	} else if (!(strcasecmp(askbuf, "s"))) {
		switches();
	} else if ((!(strcasecmp(askbuf, "c")) || (askbuf[0] == 0))) {
		DDPut(sd[eusavedstr]);
		saveuserbase(&user);
		return 1;
	}
	return 0;
}