Exemple #1
0
static char *mktoken(const char *hash, const char *t, time_t now)
{
	char now_s[NUMBUFSIZE];
	char *p;
	unsigned char *q;
	int i;
	char *r;

	libmail_strh_time_t(now, now_s);

	p=malloc(strlen(hash)+strlen(now_s)+3+hmac_sha1.hh_L*2);

	if (!p)
		return (NULL);

	strcat(strcpy(p, hash), now_s);

	q=malloc(hmac_sha1.hh_L*3);

	if (!q)
	{
		free(p);
		return (NULL);
	}

	hmac_hashkey(&hmac_sha1, t, sizeof(cur_token),
		     q, q + hmac_sha1.hh_L);
	hmac_hashtext(&hmac_sha1, p, strlen(p),
		      q, q + hmac_sha1.hh_L, q + hmac_sha1.hh_L*2);

	strcpy(p, now_s);
	r=p + strlen(p);
	*r++='-';

	for (i=0; i<hmac_sha1.hh_L; i++)
	{
		int c=(unsigned char)q[hmac_sha1.hh_L*2+i];

		*r++ = xdigit[c / 16];
		*r++ = xdigit[c % 16];
	}
	*r=0;
	free(q);
	return (p);
}
Exemple #2
0
std::string mail::imaphmac::operator()(std::string password, std::string challenge) const
{
	std::string i, o, b;

	i.insert(i.end(), hmac.hh_L, (char)0);
	o.insert(o.end(), hmac.hh_L, (char)0);
	b.insert(b.end(), hmac.hh_L, (char)0);

	hmac_hashkey( &hmac, &*password.begin(), password.size(),
		      (unsigned char *)&*o.begin(),
		      (unsigned char *)&*i.begin());

	hmac_hashtext( &hmac, &*challenge.begin(), challenge.size(),
		       (unsigned char *)&*o.begin(),
		       (unsigned char *)&*i.begin(),
		       (unsigned char *)&*b.begin());
	return (b);
}
Exemple #3
0
int main()
{
unsigned i, j;

	for (i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++)
	{
	SHA1_DIGEST ok, ik, hash;

		hmac_hashkey(&hmac_sha1, testcases[i].key,
			strlen(testcases[i].key), ok, ik);

		hmac_hashtext(&hmac_sha1, testcases[i].data,
			strlen(testcases[i].data), ok, ik, hash);

		printf("test_cases[%i].digest=0x", i+1);
		for (j=0; j<SHA1_DIGEST_SIZE; j++)
			printf("%02x", hash[j]);
		printf("\n");
	}
	return (0);
}