Ejemplo n.º 1
0
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));

	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
			     DES_ENCRYPT);
	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
			     ks3, &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
			     DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
}

ATF_TC_WITHOUT_HEAD(pcbc);
#if defined(LIBDES_LIT)
ATF_TC_BODY(pcbc, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(pcbc, tc)
{
	int j;
	unsigned char cbc_in[40], cbc_out[40];
	des_key_schedule ks;

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &cbc_iv, DES_ENCRYPT);
	if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt encrypt error\n");
	}
	des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks, &cbc_iv,
			 DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cfb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cfb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cfb, tc)
{
	size_t i;
	des_key_schedule ks;

	printf("cfb8\n");
	cfb_test(8, cfb_cipher8);
	printf("cfb16\n");
	cfb_test(16, cfb_cipher16);
	printf("cfb32\n");
	cfb_test(32, cfb_cipher32);
	printf("cfb48\n");
	cfb_test(48, cfb_cipher48);
	printf("cfb64\n");
	cfb_test(64, cfb_cipher64);

	printf("cfb64()\n");
	cfb64_test(cfb_cipher64);

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
				8, 1, ks, &cfb_tmp, DES_ENCRYPT);
	if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small encrypt error\n");
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
				8, 1, ks, &cfb_tmp, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small decrypt error\n");
	printf("ede_cfb64()\n");
	ede_cfb64_test(cfb_cipher64);
}
Ejemplo n.º 2
0
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));

	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
			     DES_ENCRYPT);
	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
			     ks3, &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
			     DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
}

ATF_TC_WITHOUT_HEAD(pcbc);
#if defined(LIBDES_LIT)
ATF_TC_BODY(pcbc, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(pcbc, tc)
{
	int j;
	unsigned char cbc_in[40], cbc_out[40];
	des_key_schedule ks;

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &cbc_iv, DES_ENCRYPT);
	if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt encrypt error\n");
	}
	des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks, &cbc_iv,
			 DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cfb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cfb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cfb, tc)
{
	size_t i;
	des_key_schedule ks;

	printf("cfb8\n");
	cfb_test(8, cfb_cipher8);
	printf("cfb16\n");
	cfb_test(16, cfb_cipher16);
	printf("cfb32\n");
	cfb_test(32, cfb_cipher32);
	printf("cfb48\n");
	cfb_test(48, cfb_cipher48);
	printf("cfb64\n");
	cfb_test(64, cfb_cipher64);

	printf("cfb64()\n");
	cfb64_test(cfb_cipher64);

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
				8, 1, ks, &cfb_tmp, DES_ENCRYPT);
	if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small encrypt error\n");
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
				8, 1, ks, &cfb_tmp, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small decrypt error\n");
	printf("ede_cfb64()\n");
	ede_cfb64_test(cfb_cipher64);
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb, tc)
{
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, ks, &ofb_tmp);
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt encrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf1[8 + 0], ofb_buf1[8 + 1],
				     ofb_buf1[8 + 2], ofb_buf1[8 + 3],
				     ofb_buf1[8 + 4], ofb_buf1[8 + 5],
				     ofb_buf1[8 + 6], ofb_buf1[8 + 7],
				     ofb_buf1[8 + 0], ofb_cipher[8 + 1],
				     ofb_cipher[8 + 2], ofb_cipher[8 + 3],
				     ofb_buf1[8 + 4], ofb_cipher[8 + 5],
				     ofb_cipher[8 + 6], ofb_cipher[8 + 7]);
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, ks,
			&ofb_tmp);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt decrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf2[8 + 0], ofb_buf2[8 + 1],
				     ofb_buf2[8 + 2], ofb_buf2[8 + 3],
				     ofb_buf2[8 + 4], ofb_buf2[8 + 5],
				     ofb_buf2[8 + 6], ofb_buf2[8 + 7],
				     plain[8 + 0], plain[8 + 1],
				     plain[8 + 2], plain[8 + 3],
				     plain[8 + 4], plain[8 + 5],
				     plain[8 + 6], plain[8 + 7]);
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, &ofb_tmp,
				  &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ede_ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, ks, ks,
				       &ofb_tmp, &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks,
			       ks, ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt decrypt error\n");
	}
}
Ejemplo n.º 3
0
	/*
	 * if (memcmp(cbc_out,cbc3_ok, (unsigned int)(strlen((char
	 * *)cbc_data)+1+7)/8*8) != 0) { printf("des_ede3_cbc_encrypt encrypt
	 * error\n"); err=1; }
	 */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	memset(iv2, '\0', sizeof iv2);
	des_ede3_cbcm_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3, &iv2,
			      DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		char buf[1024];
		int n;

		*buf = '\0';
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_data[n]);
			strlcat(buf, buf2, sizeof(buf));
		}
		strlcat(buf, ", ", sizeof(buf));
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_in[n]);
			strlcat(buf, buf2, sizeof(buf));
		}

		atf_tc_fail_nonfatal("des_ede3_cbcm_encrypt decrypt error: %s",
				     buf);
	}
}
#endif /* defined(NO_DESCBM) */

ATF_TC_WITHOUT_HEAD(ecb);
ATF_TC_BODY(ecb, tc)
{
	int i;
	des_cblock in, out, outin;
	des_key_schedule ks;

	for (i = 0; i < NUM_TESTS; i++) {
		des_set_key_unchecked(&key_data[i], ks);
		memcpy(in, plain_data[i], 8);
		memset(out, 0, 8);
		memset(outin, 0, 8);
		des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
		des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);

		if (memcmp(out, cipher_data[i], 8) != 0) {
			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s "
					     "o=%s act=%s\n", i + 1,
					     pt(key_data[i]), pt(in),
					     pt(cipher_data[i]), pt(out));
		}
		if (memcmp(in, outin, 8) != 0) {
			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s "
					     "o=%s act=%s\n", i + 1,
					     pt(key_data[i]), pt(out), pt(in),
					     pt(outin));
		}
	}
}

ATF_TC_WITHOUT_HEAD(ede_ecb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ecb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ecb, tc)
{
	int i;
	des_cblock in, out, outin;
	des_key_schedule ks, ks2, ks3;

	for (i = 0; i < (NUM_TESTS - 1); i++) {
		des_set_key_unchecked(&key_data[i], ks);
		des_set_key_unchecked(&key_data[i + 1], ks2);
		des_set_key_unchecked(&key_data[i + 2], ks3);
		memcpy(in, plain_data[i], 8);
		memset(out, 0, 8);
		memset(outin, 0, 8);
		des_ecb2_encrypt(&in, &out, ks, ks2, DES_ENCRYPT);
		des_ecb2_encrypt(&out, &outin, ks, ks2, DES_DECRYPT);

		if (memcmp(out, cipher_ecb2[i], 8) != 0) {
			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
			 i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
			       pt(out));
		}
		if (memcmp(in, outin, 8) != 0) {
			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
			i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
		}
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cbc);
ATF_TC_BODY(cbc, tc)
{
	int j;
	des_cblock iv3;
	des_key_schedule ks;
	unsigned char cbc_in[40], cbc_out[40];

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0)
		atf_tc_fail_nonfatal("Key error %d\n", j);
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ncbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc_ok, 32) != 0)
		atf_tc_fail_nonfatal("cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ncbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks,
			 &iv3, DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data)) != 0)
		atf_tc_fail_nonfatal("cbc_encrypt decrypt error\n");
}

ATF_TC_WITHOUT_HEAD(desx_cbc);
#if defined(LIBDES_LIT)
ATF_TC_BODY(desx_cbc, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(desx_cbc, tc)
{
	int j;
	des_cblock iv3;
	des_key_schedule ks;
	unsigned char cbc_in[40], cbc_out[40];

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_xcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &iv3, &cbc2_key, &cbc3_key, DES_ENCRYPT);
	if (memcmp(cbc_out, xcbc_ok, 32) != 0) {
		atf_tc_fail_nonfatal("des_xcbc_encrypt encrypt error\n");
	}
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_xcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks,
			 &iv3, &cbc2_key, &cbc3_key, DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		atf_tc_fail_nonfatal("des_xcbc_encrypt decrypt error\n");
	}
}
Ejemplo n.º 4
0
ATF_TC_BODY(ede_cbc, tc)
{
	int i, j;
	des_cblock iv3;
	des_key_schedule ks, ks2, ks3;
	unsigned char cbc_in[40], cbc_out[40];

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0)
		atf_tc_fail_nonfatal("Key error %d\n", j);
	if ((j = des_set_key_checked(&cbc2_key, ks2)) != 0)
		atf_tc_fail_nonfatal("Key error %d\n", j);
	if ((j = des_set_key_checked(&cbc3_key, ks3)) != 0)
		atf_tc_fail_nonfatal("Key error %d\n", j);
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	i = strlen((char *) cbc_data) + 1;
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));

	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
			     DES_ENCRYPT);
	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
			     ks3, &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
			     DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
}
Ejemplo n.º 5
0
ATF_TC_BODY(pow_zero_y, tc)
{
#ifndef __vax__
	const double x[] =  { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
	const double z = 0.0L / 0.0L;
	size_t i;

	/*
	 * For any value of x (including NaN),
	 * if y is +0.0 or -0.0, 1.0 is returned.
	 */
	if (pow(z, +0.0) != 1.0)
		atf_tc_fail_nonfatal("pow(NaN, +0.0) != 1.0");

	if (pow(z, -0.0) != 1.0)
		atf_tc_fail_nonfatal("pow(NaN, -0.0) != 1.0");

	for (i = 0; i < __arraycount(x); i++) {

		if (pow(x[i], +0.0) != 1.0)
			atf_tc_fail_nonfatal("pow(%0.01f, +0.0) != 1.0", x[i]);

		if (pow(x[i], -0.0) != 1.0)
			atf_tc_fail_nonfatal("pow(%0.01f, -0.0) != 1.0", x[i]);
	}
#endif
}
Ejemplo n.º 6
0
	/*
	 * if (memcmp(cbc_out,cbc3_ok, (unsigned int)(strlen((char
	 * *)cbc_data)+1+7)/8*8) != 0) { printf("des_ede3_cbc_encrypt encrypt
	 * error\n"); err=1; }
	 */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	memset(iv2, '\0', sizeof iv2);
	des_ede3_cbcm_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3, &iv2,
			      DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		char buf[1024];
		int n;

		*buf = '\0';
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_data[n]);
			strlcat(buf, buf2, sizeof(buf));
		}
		strlcat(buf, ", ", sizeof(buf));
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_in[n]);
			strlcat(buf, buf2, sizeof(buf));
		}

		atf_tc_fail_nonfatal("des_ede3_cbcm_encrypt decrypt error: %s",
				     buf);
	}
}
#endif /* defined(NO_DESCBM) */

ATF_TC_WITHOUT_HEAD(ecb);
ATF_TC_BODY(ecb, tc)
{
	int i;
	des_cblock in, out, outin;
	des_key_schedule ks;

	for (i = 0; i < NUM_TESTS; i++) {
		des_set_key_unchecked(&key_data[i], ks);
		memcpy(in, plain_data[i], 8);
		memset(out, 0, 8);
		memset(outin, 0, 8);
		des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
		des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);

		if (memcmp(out, cipher_data[i], 8) != 0) {
			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s "
					     "o=%s act=%s\n", i + 1,
					     pt(key_data[i]), pt(in),
					     pt(cipher_data[i]), pt(out));
		}
		if (memcmp(in, outin, 8) != 0) {
			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s "
					     "o=%s act=%s\n", i + 1,
					     pt(key_data[i]), pt(out), pt(in),
					     pt(outin));
		}
	}
}

ATF_TC_WITHOUT_HEAD(ede_ecb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ecb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ecb, tc)
{
	int i;
	des_cblock in, out, outin;
	des_key_schedule ks, ks2, ks3;

	for (i = 0; i < (NUM_TESTS - 1); i++) {
		des_set_key_unchecked(&key_data[i], ks);
		des_set_key_unchecked(&key_data[i + 1], ks2);
		des_set_key_unchecked(&key_data[i + 2], ks3);
		memcpy(in, plain_data[i], 8);
		memset(out, 0, 8);
		memset(outin, 0, 8);
		des_ecb2_encrypt(&in, &out, ks, ks2, DES_ENCRYPT);
		des_ecb2_encrypt(&out, &outin, ks, ks2, DES_DECRYPT);

		if (memcmp(out, cipher_ecb2[i], 8) != 0) {
			atf_tc_fail_nonfatal("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
			 i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
			       pt(out));
		}
		if (memcmp(in, outin, 8) != 0) {
			atf_tc_fail_nonfatal("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
			i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
		}
	}
}
Ejemplo n.º 7
0
ATF_TC_BODY(powf_inf_neg_x, tc)
{
	const float x = -1.0L / 0.0L;
	float z;

	/*
	 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
	 * If y is even, y > 0, and x is -Inf, +Inf is returned.
	 */
	z = powf(x, 3.0);

	if (isinff(z) == 0 || signbit(z) == 0)
		atf_tc_fail_nonfatal("powf(-Inf, 3.0) != -Inf");

	z = powf(x, 4.0);

	if (isinff(z) == 0 || signbit(z) != 0)
		atf_tc_fail_nonfatal("powf(-Inf, 4.0) != +Inf");

	/*
	 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
	 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
	 */
	z = powf(x, -3.0);

	if (fabsf(z) > 0.0 || signbit(z) == 0) {
		atf_tc_expect_fail("PR lib/45372");
		atf_tc_fail_nonfatal("powf(-Inf, -3.0) != -0.0");
	}

	z = powf(x, -4.0);

	if (fabsf(z) > 0.0 || signbit(z) != 0)
		atf_tc_fail_nonfatal("powf(-Inf -4.0) != +0.0");
}
Ejemplo n.º 8
0
ATF_TC_BODY(powf_zero_y, tc)
{
	const float x[] =  { 0.1, -3.0, 77.0, 99.99, 101.0000001 };
	const float z = 0.0L / 0.0L;
	size_t i;

	/*
	 * For any value of x (including NaN),
	 * if y is +0.0 or -0.0, 1.0 is returned.
	 */
	if (powf(z, +0.0) != 1.0)
		atf_tc_fail_nonfatal("powf(NaN, +0.0) != 1.0");

	if (powf(z, -0.0) != 1.0)
		atf_tc_fail_nonfatal("powf(NaN, -0.0) != 1.0");

	for (i = 0; i < __arraycount(x); i++) {

		if (powf(x[i], +0.0) != 1.0)
			atf_tc_fail_nonfatal("powf(%0.01f, +0.0) != 1.0",x[i]);

		if (powf(x[i], -0.0) != 1.0)
			atf_tc_fail_nonfatal("powf(%0.01f, -0.0) != 1.0",x[i]);
	}
}
Ejemplo n.º 9
0
ATF_TC_BODY(pow_inf_neg_x, tc)
{
	const double x = -1.0L / 0.0L;
	double z;

	/*
	 * If y is odd, y > 0, and x is -Inf, -Inf is returned.
	 * If y is even, y > 0, and x is -Inf, +Inf is returned.
	 */
	z = pow(x, 3.0);

	if (isinf(z) == 0 || signbit(z) == 0)
		atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf");

	z = pow(x, 4.0);

	if (isinf(z) == 0 || signbit(z) != 0)
		atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf");

	/*
	 * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
	 * If y is even, y < 0, and x is -Inf, +0.0 is returned.
	 */
	z = pow(x, -3.0);

	if (fabs(z) > 0.0 || signbit(z) == 0)
		atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0");

	z = pow(x, -4.0);

	if (fabs(z) > 0.0 || signbit(z) != 0)
		atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0");
}
Ejemplo n.º 10
0
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));

	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
			     DES_ENCRYPT);
	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
			     ks3, &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
			     DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
}

ATF_TC_WITHOUT_HEAD(pcbc);
#if defined(LIBDES_LIT)
ATF_TC_BODY(pcbc, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(pcbc, tc)
{
	int j;
	unsigned char cbc_in[40], cbc_out[40];
	des_key_schedule ks;

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &cbc_iv, DES_ENCRYPT);
	if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt encrypt error\n");
	}
	des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks, &cbc_iv,
			 DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cfb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cfb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cfb, tc)
{
	size_t i;
	des_key_schedule ks;

	printf("cfb8\n");
	cfb_test(8, cfb_cipher8);
	printf("cfb16\n");
	cfb_test(16, cfb_cipher16);
	printf("cfb32\n");
	cfb_test(32, cfb_cipher32);
	printf("cfb48\n");
	cfb_test(48, cfb_cipher48);
	printf("cfb64\n");
	cfb_test(64, cfb_cipher64);

	printf("cfb64()\n");
	cfb64_test(cfb_cipher64);

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
				8, 1, ks, &cfb_tmp, DES_ENCRYPT);
	if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small encrypt error\n");
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
				8, 1, ks, &cfb_tmp, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small decrypt error\n");
	printf("ede_cfb64()\n");
	ede_cfb64_test(cfb_cipher64);
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb, tc)
{
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, ks, &ofb_tmp);
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt encrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf1[8 + 0], ofb_buf1[8 + 1],
				     ofb_buf1[8 + 2], ofb_buf1[8 + 3],
				     ofb_buf1[8 + 4], ofb_buf1[8 + 5],
				     ofb_buf1[8 + 6], ofb_buf1[8 + 7],
				     ofb_buf1[8 + 0], ofb_cipher[8 + 1],
				     ofb_cipher[8 + 2], ofb_cipher[8 + 3],
				     ofb_buf1[8 + 4], ofb_cipher[8 + 5],
				     ofb_cipher[8 + 6], ofb_cipher[8 + 7]);
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, ks,
			&ofb_tmp);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt decrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf2[8 + 0], ofb_buf2[8 + 1],
				     ofb_buf2[8 + 2], ofb_buf2[8 + 3],
				     ofb_buf2[8 + 4], ofb_buf2[8 + 5],
				     ofb_buf2[8 + 6], ofb_buf2[8 + 7],
				     plain[8 + 0], plain[8 + 1],
				     plain[8 + 2], plain[8 + 3],
				     plain[8 + 4], plain[8 + 5],
				     plain[8 + 6], plain[8 + 7]);
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, &ofb_tmp,
				  &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ede_ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, ks, ks,
				       &ofb_tmp, &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks,
			       ks, ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cbc_cksum);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cbc_cksum, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cbc_cksum, tc)
{
	unsigned char cret[8];
	des_key_schedule ks;
	DES_LONG cs;

	des_set_key_checked(&cbc_key, ks);
	cs = des_cbc_cksum(cbc_data, &cret, strlen((char *) cbc_data), ks, &cbc_iv);
	if (cs != cbc_cksum_ret) {
		atf_tc_fail_nonfatal("bad return value (%08lX), should be %08lX\n",
		       (unsigned long) cs, (unsigned long) cbc_cksum_ret);
	}
	if (memcmp(cret, cbc_cksum_data, 8) != 0) {
		atf_tc_fail_nonfatal("bad cbc_cksum block returned\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(quad_cksum);
#if defined(LIBDES_LIT)
ATF_TC_BODY(quad_cksum, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(quad_cksum, tc)
{
	DES_LONG cs, lqret[4];

	cs = quad_cksum(cbc_data, (des_cblock *) lqret,
		(long) strlen((char *) cbc_data), 2, (des_cblock *) cbc_iv);
	if (cs != 0x70d7a63aL) {
		atf_tc_fail_nonfatal("quad_cksum error, ret %08lx should be 70d7a63a\n",
		       (unsigned long) cs);
	}
	if (lqret[0] != 0x327eba8dL) {
		atf_tc_fail_nonfatal("quad_cksum error, out[0] %08lx is not %08lx\n",
		       (unsigned long) lqret[0], 0x327eba8dUL);
	}
	if (lqret[1] != 0x201a49ccL) {
		atf_tc_fail_nonfatal("quad_cksum error, out[1] %08lx is not %08lx\n",
		       (unsigned long) lqret[1], 0x201a49ccUL);
	}
	if (lqret[2] != 0x70d7a63aL) {
		atf_tc_fail_nonfatal("quad_cksum error, out[2] %08lx is not %08lx\n",
		       (unsigned long) lqret[2], 0x70d7a63aUL);
	}
	if (lqret[3] != 0x501c2c26L) {
		atf_tc_fail_nonfatal("quad_cksum error, out[3] %08lx is not %08lx\n",
		       (unsigned long) lqret[3], 0x501c2c26UL);
	}
}
Ejemplo n.º 11
0
/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
static unsigned char cbc_data[40] = {
	0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
	0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
	0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20,
	0x66, 0x6F, 0x72, 0x20, 0x00, 0x31, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

static unsigned char cbc_ok[32] = {
	0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
	0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb,
	0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68,
	0x1d, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4,
};

#ifdef SCREW_THE_PARITY
#error "SCREW_THE_PARITY is not ment to be defined."
#error "Original vectors are preserved for reference only."
static unsigned char cbc2_key[8] = {
	0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
};
static unsigned char xcbc_ok[32] = {
	0x86, 0x74, 0x81, 0x0D, 0x61, 0xA4, 0xA5, 0x48,
	0xB9, 0x93, 0x03, 0xE1, 0xB8, 0xBB, 0xBD, 0xBD,
	0x64, 0x30, 0x0B, 0xB9, 0x06, 0x65, 0x81, 0x76,
	0x04, 0x1D, 0x77, 0x62, 0x17, 0xCA, 0x2B, 0xD2,
};
#else
static unsigned char xcbc_ok[32] = {
	0x84, 0x6B, 0x29, 0x14, 0x85, 0x1E, 0x9A, 0x29,
	0x54, 0x73, 0x2F, 0x8A, 0xA0, 0xA6, 0x11, 0xC1,
	0x15, 0xCD, 0xC2, 0xD7, 0x95, 0x1B, 0x10, 0x53,
	0xA6, 0x3C, 0x5E, 0x03, 0xB2, 0x1A, 0xA3, 0xC4,
};
#endif

static unsigned char cbc3_ok[32] = {
	0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0,
	0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC,
	0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4,
	0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75
};

static unsigned char pcbc_ok[32] = {
	0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
	0x6d, 0xec, 0xb4, 0x70, 0xa0, 0xe5, 0x6b, 0x15,
	0xae, 0xa6, 0xbf, 0x61, 0xed, 0x7d, 0x9c, 0x9f,
	0xf7, 0x17, 0x46, 0x3b, 0x8a, 0xb3, 0xcc, 0x88
};

static unsigned char cfb_key[8] = {
	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static unsigned char cfb_iv[8] = {
	0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
};
static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
static unsigned char plain[24] =
{
	0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
	0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
	0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
	0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
};
static unsigned char cfb_cipher8[24] = {
	0xf3, 0x1f, 0xda, 0x07, 0x01, 0x14,
	0x62, 0xee, 0x18, 0x7f, 0x43, 0xd8,
	0x0a, 0x7c, 0xd9, 0xb5, 0xb0, 0xd2,
	0x90, 0xda, 0x6e, 0x5b, 0x9a, 0x87,
};
static unsigned char cfb_cipher16[24] = {
	0xF3, 0x09, 0x87, 0x87, 0x7F, 0x57,
	0xF7, 0x3C, 0x36, 0xB6, 0xDB, 0x70,
	0xD8, 0xD5, 0x34, 0x19, 0xD3, 0x86,
	0xB2, 0x23, 0xB7, 0xB2, 0xAD, 0x1B,
};
static unsigned char cfb_cipher32[24] = {
	0xF3, 0x09, 0x62, 0x49, 0xA4, 0xDF,
	0xA4, 0x9F, 0x33, 0xDC, 0x7B, 0xAD,
	0x4C, 0xC8, 0x9F, 0x64, 0xE4, 0x53,
	0xE5, 0xEC, 0x67, 0x20, 0xDA, 0xB6,
};
static unsigned char cfb_cipher48[24] = {
	0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4,
	0x30, 0xB5, 0x15, 0xEC, 0xBB, 0x85,
	0x97, 0x5A, 0x13, 0x8C, 0x68, 0x60,
	0xE2, 0x38, 0x34, 0x3C, 0xDC, 0x1F,
};
static unsigned char cfb_cipher64[24] = {
	0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4,
	0x6E, 0x51, 0xA6, 0x9E, 0x83, 0x9B,
	0x1A, 0x92, 0xF7, 0x84, 0x03, 0x46,
	0x71, 0x33, 0x89, 0x8E, 0xA6, 0x22,
};

static unsigned char ofb_key[8] = {
	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static unsigned char ofb_iv[8] = {
	0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
};
static unsigned char ofb_buf1[24], ofb_buf2[24], ofb_tmp[8];
static unsigned char ofb_cipher[24] =
{
	0xf3, 0x09, 0x62, 0x49, 0xc7, 0xf4, 0x6e, 0x51,
	0x35, 0xf2, 0x4a, 0x24, 0x2e, 0xeb, 0x3d, 0x3f,
	0x3d, 0x6d, 0x5b, 0xe3, 0x25, 0x5a, 0xf8, 0xc3
};

static DES_LONG cbc_cksum_ret = 0xB462FEF7L;
static unsigned char cbc_cksum_data[8] = {
	0x1D, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4,
};

static char *
pt(unsigned char *p)
{
	static char bufs[10][20];
	static int bnum = 0;
	char *ret;
	int i;
	static const char *f = "0123456789ABCDEF";

	ret = &(bufs[bnum++][0]);
	bnum %= 10;
	for (i = 0; i < 8; i++) {
		ret[i * 2] = f[(p[i] >> 4) & 0xf];
		ret[i * 2 + 1] = f[p[i] & 0xf];
	}
	ret[16] = '\0';
	return (ret);
}

static void
fail_cfb_buf(const char *msg, unsigned char *ptr)
{
	char buf[1024];
	int i;

	*buf = '\0';
	for (i = 0; i < 24; i += 8) {
		char buf2[128];
		snprintf(buf2, sizeof(buf2), "%s /", pt(&(cfb_buf1[i])));
		strlcat(buf, buf2, sizeof(buf));
	}

	atf_tc_fail_nonfatal("%s: %s", msg, buf);
}

#if !defined(LIBDES_LIT)
static void
cfb_test(int bits, unsigned char *cfb_cipher)
{
	des_key_schedule ks;

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	des_cfb_encrypt(plain, cfb_buf1, bits, sizeof(plain), ks, &cfb_tmp,
			DES_ENCRYPT);
	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
		fail_cfb_buf("cfb_encrypt encrypt error", cfb_buf1);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	des_cfb_encrypt(cfb_buf1, cfb_buf2, bits, sizeof(plain), ks, &cfb_tmp,
			DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		fail_cfb_buf("cfb_encrypt decrypt error", cfb_buf2);
}
#endif /* !defined(LIBDES_LIT) */

#if !defined(LIBDES_LIT)
static void
cfb64_test(unsigned char *cfb_cipher)
{
	int n;
	des_key_schedule ks;

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	n = 0;
	des_cfb64_encrypt(plain, cfb_buf1, 12, ks, &cfb_tmp, &n, DES_ENCRYPT);
	des_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), sizeof(plain) - 12, ks,
			  &cfb_tmp, &n, DES_ENCRYPT);
	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
		fail_cfb_buf("cfb_encrypt encrypt error", cfb_buf1);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	n = 0;
	des_cfb64_encrypt(cfb_buf1, cfb_buf2, 17, ks, &cfb_tmp, &n, DES_DECRYPT);
	des_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
			  sizeof(plain) - 17, ks, &cfb_tmp, &n, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		fail_cfb_buf("cfb_encrypt decrypt error", cfb_buf2);
}
#endif /* !defined(LIBDES_LIT) */

#if !defined(LIBDES_LIT)
static void
ede_cfb64_test(unsigned char *cfb_cipher)
{
	int n;
	des_key_schedule ks;

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	n = 0;
	des_ede3_cfb64_encrypt(plain, cfb_buf1, 12, ks, ks, ks, &cfb_tmp, &n,
			       DES_ENCRYPT);
	des_ede3_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]),
			       sizeof(plain) - 12, ks, ks, ks,
			       &cfb_tmp, &n, DES_ENCRYPT);
	if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0)
		fail_cfb_buf("ede_cfb_encrypt encrypt error", cfb_buf1);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	n = 0;
	des_ede3_cfb64_encrypt(cfb_buf1, cfb_buf2, (long) 17, ks, ks, ks,
			       &cfb_tmp, &n, DES_DECRYPT);
	des_ede3_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
			       sizeof(plain) - 17, ks, ks, ks,
			       &cfb_tmp, &n, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		fail_cfb_buf("ede_cfb_encrypt decrypt error", cfb_buf2);
}
#endif /* !defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cbcm);
#if defined(NO_DESCBCM)
ATF_TC_BODY(cbcm, tc)
{
	atf_tc_skip("Test program built with NO_DESCBCM");
}
#else /* defined(NO_DESCBM) */
ATF_TC_BODY(cbcm, tc)
{
	int i, j;
	des_cblock iv3, iv2;
	unsigned char cbc_in[40], cbc_out[40];
	des_key_schedule ks, ks2, ks3;

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	if ((j = des_set_key_checked(&cbc2_key, ks2)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	if ((j = des_set_key_checked(&cbc3_key, ks3)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	i = strlen((char *) cbc_data) + 1;
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	memset(iv2, '\0', sizeof iv2);

	des_ede3_cbcm_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3, &iv2,
			      DES_ENCRYPT);
	des_ede3_cbcm_encrypt(&cbc_data[16], &cbc_out[16], i - 16, ks, ks2, ks3,
			      &iv3, &iv2, DES_ENCRYPT);
	/*
	 * if (memcmp(cbc_out,cbc3_ok, (unsigned int)(strlen((char
	 * *)cbc_data)+1+7)/8*8) != 0) { printf("des_ede3_cbc_encrypt encrypt
	 * error\n"); err=1; }
	 */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	memset(iv2, '\0', sizeof iv2);
	des_ede3_cbcm_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3, &iv2,
			      DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		char buf[1024];
		int n;

		*buf = '\0';
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_data[n]);
			strlcat(buf, buf2, sizeof(buf));
		}
		strlcat(buf, ", ", sizeof(buf));
		for (n = 0; n < i; ++n) {
			char buf2[16];
			snprintf(buf2, sizeof(buf2), " %02x", cbc_in[n]);
			strlcat(buf, buf2, sizeof(buf));
		}

		atf_tc_fail_nonfatal("des_ede3_cbcm_encrypt decrypt error: %s",
				     buf);
	}
}
Ejemplo n.º 12
0
ATF_TC_BODY(fail_and_fail_check, tc)
{
    atf_tc_expect_fail("Fail first");
    atf_tc_fail_nonfatal("abc");
    atf_tc_expect_pass();

    atf_tc_expect_fail("And fail again");
    atf_tc_fail_nonfatal("def");
    atf_tc_expect_pass();
}
Ejemplo n.º 13
0
ATF_TC_BODY(fast_crypt, tc)
{
	char *str;

	str = crypt("testing", "ef");
	if (strcmp("efGnQx2725bI2", str) != 0)
		atf_tc_fail_nonfatal("fast crypt error, %s should be efGnQx2725bI2\n", str);
	str = crypt("bca76;23", "yA");
	if (strcmp("yA1Rp/1hZXIJk", str) != 0)
		atf_tc_fail_nonfatal("fast crypt error, %s should be yA1Rp/1hZXIJk\n", str);
}
Ejemplo n.º 14
0
ATF_TC_BODY(fail_but_pass, tc)
{
    atf_tc_expect_fail("Fail first");
    atf_tc_fail_nonfatal("abc");
    atf_tc_expect_pass();

    atf_tc_expect_fail("Will not fail");
    atf_tc_expect_pass();

    atf_tc_expect_fail("And fail again");
    atf_tc_fail_nonfatal("def");
    atf_tc_expect_pass();
}
Ejemplo n.º 15
0
static void
check(struct test *t, long int li, long long int lli, char *end)
{

	if (li != -1 && li != t->res)
		atf_tc_fail_nonfatal("strtol(%s, &end, %d) failed "
		    "(rv = %ld)", t->str, t->base, li);

	if (lli != -1 && lli != t->res)
		atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
		    "(rv = %lld)", t->str, t->base, lli);

	if (t->end != NULL && strcmp(t->end, end) != 0)
		atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
		    "strtol(%s, &end, %d)", end, t->str, t->base);
}
Ejemplo n.º 16
0
ATF_TC_BODY(cosh_zero_pos, tc)
{
	const double x = 0.0L;

	if (cosh(x) != 1.0)
		atf_tc_fail_nonfatal("cosh(+0.0) != 1.0");
}
Ejemplo n.º 17
0
ATF_TC_BODY(coshf_zero_pos, tc)
{
	const float x = 0.0L;

	if (coshf(x) != 1.0)
		atf_tc_fail_nonfatal("coshf(+0.0) != 1.0");
}
Ejemplo n.º 18
0
ATF_TC_BODY(fopen_mode, tc)
{
	size_t i;
	FILE *f;

	static const char *mode[] = {
		"r", "r+", "w", "w+", "a", "a+",
		"rb", "r+b", "wb", "w+b", "ab", "a+b"
		"re", "r+e", "we", "w+e", "ae", "a+e"
		"rf", "r+f", "wf", "w+f", "af", "a+f"
	};

	f = fopen(path, "w+");

	ATF_REQUIRE(f != NULL);
	ATF_REQUIRE(fclose(f) == 0);

	/*
	 * Verify that various modes work.
	 */
	for (i = 0; i < __arraycount(mode); i++) {

		f = fopen(path, mode[i]);

		if (f != NULL) {
			ATF_REQUIRE(fclose(f) == 0);
			continue;
		}

		atf_tc_fail_nonfatal("failed to open file as %s",  mode[i]);
	}

	(void)unlink(path);
}
Ejemplo n.º 19
0
ATF_TC_BODY(fopen_regular, tc)
{
	static const char *mode[] = { "rf", "r+f", "wf", "w+f", "af", "a+f" };
	static const char *devs[] = { _PATH_DEVNULL };

	size_t i, j;
	FILE *f;

	for (i = 0; i < __arraycount(devs); i++) {

		for (j = 0; j < __arraycount(mode); j++) {

			errno = 0;
			f = fopen(devs[i], mode[j]);

			if (f == NULL && errno == EFTYPE)
				continue;

			if (f != NULL)
				(void)fclose(f);

			atf_tc_fail_nonfatal("opened %s as %s",
			    devs[i], mode[j]);
		}
	}
}
Ejemplo n.º 20
0
ATF_TC_BODY(erf_inf_neg, tc)
{
	const double x = -1.0L / 0.0L;

	if (erf(x) != -1.0)
		atf_tc_fail_nonfatal("erf(-Inf) != -1.0");
}
Ejemplo n.º 21
0
ATF_TC_BODY(erf_inf_pos, tc)
{
	const double x = 1.0L / 0.0L;

	if (erf(x) != 1.0)
		atf_tc_fail_nonfatal("erf(+Inf) != 1.0");
}
Ejemplo n.º 22
0
ATF_TC_BODY(strvis_basic, tc)
{
	char *srcbuf, *dstbuf, *visbuf;
	unsigned int i, j;

	ATF_REQUIRE((dstbuf = malloc(SIZE)) != NULL);
	ATF_REQUIRE((srcbuf = malloc(SIZE)) != NULL);
	ATF_REQUIRE((visbuf = malloc(SIZE * 4 + 1)) != NULL);

	for (i = 0; i < SIZE; i++)
		srcbuf[i] = (char)i;

	for (i = 0; i < __arraycount(styles); i++) {
		ATF_REQUIRE(strsvisx(visbuf, srcbuf, SIZE, styles[i], "") > 0);
		memset(dstbuf, 0, SIZE);
		ATF_REQUIRE(strunvisx(dstbuf, visbuf, 
		    styles[i] & (VIS_HTTP1808|VIS_MIMESTYLE)) > 0);
		for (j = 0; j < SIZE; j++)
			if (dstbuf[j] != (char)j)
				atf_tc_fail_nonfatal("Failed for style %x, "
				    "char %d [%d]", styles[i], j, dstbuf[j]);
	}
	free(dstbuf);
	free(srcbuf);
	free(visbuf);
}
Ejemplo n.º 23
0
ATF_TC_BODY(erfcf_inf_neg, tc)
{
	const float x = -1.0L / 0.0L;

	if (erfcf(x) != 2.0)
		atf_tc_fail_nonfatal("erfcf(-Inf) != 2.0");
}
Ejemplo n.º 24
0
	/* i=((i+7)/8)*8; */
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));

	des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
			     DES_ENCRYPT);
	des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
			     ks3, &iv3, DES_ENCRYPT);
	if (memcmp(cbc_out, cbc3_ok, (unsigned int)
		   (strlen((char *) cbc_data) + 1 + 7) / 8 * 8) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt encrypt error\n");
	memcpy(iv3, cbc_iv, sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3,
			     DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0)
		atf_tc_fail_nonfatal("des_ede3_cbc_encrypt decrypt error\n");
}

ATF_TC_WITHOUT_HEAD(pcbc);
#if defined(LIBDES_LIT)
ATF_TC_BODY(pcbc, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(pcbc, tc)
{
	int j;
	unsigned char cbc_in[40], cbc_out[40];
	des_key_schedule ks;

	if ((j = des_set_key_checked(&cbc_key, ks)) != 0) {
		atf_tc_fail_nonfatal("Key error %d\n", j);
	}
	memset(cbc_out, 0, 40);
	memset(cbc_in, 0, 40);
	des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *) cbc_data) + 1, ks,
			 &cbc_iv, DES_ENCRYPT);
	if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt encrypt error\n");
	}
	des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *) cbc_data) + 1, ks, &cbc_iv,
			 DES_DECRYPT);
	if (memcmp(cbc_in, cbc_data, strlen((char *) cbc_data) + 1) != 0) {
		atf_tc_fail_nonfatal("pcbc_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cfb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cfb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cfb, tc)
{
	size_t i;
	des_key_schedule ks;

	printf("cfb8\n");
	cfb_test(8, cfb_cipher8);
	printf("cfb16\n");
	cfb_test(16, cfb_cipher16);
	printf("cfb32\n");
	cfb_test(32, cfb_cipher32);
	printf("cfb48\n");
	cfb_test(48, cfb_cipher48);
	printf("cfb64\n");
	cfb_test(64, cfb_cipher64);

	printf("cfb64()\n");
	cfb64_test(cfb_cipher64);

	des_set_key_checked(&cfb_key, ks);
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
				8, 1, ks, &cfb_tmp, DES_ENCRYPT);
	if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small encrypt error\n");
	memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
	for (i = 0; i < sizeof(plain); i++)
		des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
				8, 1, ks, &cfb_tmp, DES_DECRYPT);
	if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0)
		atf_tc_fail_nonfatal("cfb_encrypt small decrypt error\n");
	printf("ede_cfb64()\n");
	ede_cfb64_test(cfb_cipher64);
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb, tc)
{
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, ks, &ofb_tmp);
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt encrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf1[8 + 0], ofb_buf1[8 + 1],
				     ofb_buf1[8 + 2], ofb_buf1[8 + 3],
				     ofb_buf1[8 + 4], ofb_buf1[8 + 5],
				     ofb_buf1[8 + 6], ofb_buf1[8 + 7],
				     ofb_buf1[8 + 0], ofb_cipher[8 + 1],
				     ofb_cipher[8 + 2], ofb_cipher[8 + 3],
				     ofb_buf1[8 + 4], ofb_cipher[8 + 5],
				     ofb_cipher[8 + 6], ofb_cipher[8 + 7]);
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	des_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, ks,
			&ofb_tmp);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb_encrypt decrypt error: "
				     "%02X %02X %02X %02X %02X %02X %02X %02X, "
				     "%02X %02X %02X %02X %02X %02X %02X %02X",
				     ofb_buf2[8 + 0], ofb_buf2[8 + 1],
				     ofb_buf2[8 + 2], ofb_buf2[8 + 3],
				     ofb_buf2[8 + 4], ofb_buf2[8 + 5],
				     ofb_buf2[8 + 6], ofb_buf2[8 + 7],
				     plain[8 + 0], plain[8 + 1],
				     plain[8 + 2], plain[8 + 3],
				     plain[8 + 4], plain[8 + 5],
				     plain[8 + 6], plain[8 + 7]);
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, &ofb_tmp,
				  &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ofb64_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(ede_ofb64);
#if defined(LIBDES_LIT)
ATF_TC_BODY(ede_ofb64, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(ede_ofb64, tc)
{
	int num;
	size_t i;
	des_key_schedule ks;

	des_set_key_checked(&ofb_key, ks);
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	memset(ofb_buf1, 0, sizeof(ofb_buf1));
	memset(ofb_buf2, 0, sizeof(ofb_buf1));
	num = 0;
	for (i = 0; i < sizeof(plain); i++) {
		des_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, ks, ks,
				       &ofb_tmp, &num);
	}
	if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt encrypt error\n");
	}
	memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
	num = 0;
	des_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks,
			       ks, ks, &ofb_tmp, &num);
	if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
		atf_tc_fail_nonfatal("ede_ofb64_encrypt decrypt error\n");
	}
}
#endif /* defined(LIBDES_LIT) */

ATF_TC_WITHOUT_HEAD(cbc_cksum);
#if defined(LIBDES_LIT)
ATF_TC_BODY(cbc_cksum, tc)
{
	atf_tc_skip("Test program built with LIBDES_LIT");
}
#else /* defined(LIBDES_LIT) */
ATF_TC_BODY(cbc_cksum, tc)
{
	unsigned char cret[8];
	des_key_schedule ks;
	DES_LONG cs;

	des_set_key_checked(&cbc_key, ks);
	cs = des_cbc_cksum(cbc_data, &cret, strlen((char *) cbc_data), ks, &cbc_iv);
	if (cs != cbc_cksum_ret) {
		atf_tc_fail_nonfatal("bad return value (%08lX), should be %08lX\n",
		       (unsigned long) cs, (unsigned long) cbc_cksum_ret);
	}
	if (memcmp(cret, cbc_cksum_data, 8) != 0) {
		atf_tc_fail_nonfatal("bad cbc_cksum block returned\n");
	}
}
Ejemplo n.º 25
0
ATF_TC_BODY(erfc_inf_pos, tc)
{
	const double x = 1.0L / 0.0L;
	double y = erfc(x);

	if (fabs(y) > 0.0 || signbit(y) != 0)
		atf_tc_fail_nonfatal("erfc(+Inf) != +0.0");
}
Ejemplo n.º 26
0
ATF_TC_BODY(erfcf_inf_pos, tc)
{
	const float x = 1.0L / 0.0L;
	float y = erfcf(x);

	if (fabsf(y) > 0.0 || signbit(y) != 0)
		atf_tc_fail_nonfatal("erfcf(+Inf) != +0.0");
}
Ejemplo n.º 27
0
ATF_TC_BODY(sinhf_zero_pos, tc)
{
	const float x = 0.0L;
	float y = sinhf(x);

	if (fabsf(y) > 0.0 || signbit(y) != 0)
		atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
}
Ejemplo n.º 28
0
ATF_TC_BODY(sinhf_zero_neg, tc)
{
	const float x = -0.0L;
	float y = sinhf(x);

	if (fabsf(y) > 0.0 || signbit(y) == 0)
		atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
}
Ejemplo n.º 29
0
ATF_TC_BODY(sinh_zero_pos, tc)
{
	const double x = 0.0L;
	double y = sinh(x);

	if (fabs(y) > 0.0 || signbit(y) != 0)
		atf_tc_fail_nonfatal("sinh(+0.0) != +0.0");
}
Ejemplo n.º 30
0
ATF_TC_BODY(sinh_zero_neg, tc)
{
	const double x = -0.0L;
	double y = sinh(x);

	if (fabs(y) > 0.0 || signbit(y) == 0)
		atf_tc_fail_nonfatal("sinh(-0.0) != -0.0");
}