Exemple #1
0
void
fixup_quad_cksum(void *start, size_t len, des_cblock *key, 
		 void *new_checksum, void *old_checksum, int little)
{
    des_quad_cksum((des_cblock*)start, (des_cblock*)new_checksum, len, 2, key);
    if(HOST_BYTE_ORDER){
	if(little){
	    memcpy(old_checksum, new_checksum, 16);
	}else{
	    u_int32_t *tmp = (u_int32_t*)new_checksum;
	    memcpy(old_checksum, new_checksum, 16);
	    swap_u_16(old_checksum);
	    swap_u_long(tmp[0]);
	    swap_u_long(tmp[1]);
	    swap_u_long(tmp[2]);
	    swap_u_long(tmp[3]);
	}
    }else{
	if(little){
	    u_int32_t *tmp = (u_int32_t*)new_checksum;
	    swap_u_long(tmp[0]);
	    swap_u_long(tmp[1]);
	    swap_u_long(tmp[2]);
	    swap_u_long(tmp[3]);
	    memcpy(old_checksum, new_checksum, 16);
	}else{
	    u_int32_t tmp[4];
	    tmp[0] = ((u_int32_t*)new_checksum)[3];
	    tmp[1] = ((u_int32_t*)new_checksum)[2];
	    tmp[2] = ((u_int32_t*)new_checksum)[1];
	    tmp[3] = ((u_int32_t*)new_checksum)[0];
	    memcpy(old_checksum, tmp, 16);
	}
    }
}
Exemple #2
0
Code_t
ZFormatAuthenticNotice(ZNotice_t *notice,
		       char *buffer,
		       int buffer_len,
		       int *len,
		       C_Block session)
{
    ZNotice_t newnotice;
    char *ptr;
    int retval, hdrlen;

    newnotice = *notice;
    newnotice.z_auth = 1;
    newnotice.z_authent_len = 0;
    newnotice.z_ascii_authent = "";

    if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
				    &hdrlen, &ptr, NULL)) != ZERR_NONE)
	return (retval);

    newnotice.z_checksum =
	(ZChecksum_t)des_quad_cksum((void *)buffer, NULL, ptr - buffer, 0, (C_Block *)session);

    if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
				    &hdrlen, NULL, NULL)) != ZERR_NONE)
	return (retval);

    ptr = buffer+hdrlen;

    if (newnotice.z_message_len+hdrlen > buffer_len)
	return (ZERR_PKTLEN);

    (void) memcpy(ptr, newnotice.z_message, newnotice.z_message_len);

    *len = hdrlen+newnotice.z_message_len;

    if (*len > Z_MAXPKTLEN)
	return (ZERR_PKTLEN);

    return (ZERR_NONE);
}
Exemple #3
0
int main(int argc, char *argv[])
	{
	int j,err=0;
	unsigned int i;
	des_cblock in,out,outin,iv3,iv2;
	des_key_schedule ks,ks2,ks3;
	unsigned char cbc_in[40];
	unsigned char cbc_out[40];
	DES_LONG cs;
	unsigned char cret[8];
#ifdef _CRAY
        struct {
            int a:32;
            int b:32;
        } lqret[2];
#else
        DES_LONG lqret[4];
#endif
	int num;
	char *str;

#ifndef OPENSSL_NO_DESCBCM
	TINYCLR_SSL_PRINTF("Doing cbcm\n");
	if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	TINYCLR_SSL_MEMSET(cbc_out,0,40);
	TINYCLR_SSL_MEMSET(cbc_in,0,40);
	i=TINYCLR_SSL_STRLEN((char *)cbc_data)+1;
	/* i=((i+7)/8)*8; */
	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	TINYCLR_SSL_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)(TINYCLR_SSL_STRLEN((char *)cbc_data)+1+7)/8*8) != 0)
		{
		TINYCLR_SSL_PRINTF("des_ede3_cbc_encrypt encrypt error\n");
		err=1;
		}
	*/
	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	TINYCLR_SSL_MEMSET(iv2,'\0',sizeof iv2);
	DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_in,cbc_data,TINYCLR_SSL_STRLEN((char *)cbc_data)+1) != 0)
		{
		unsigned int n;

		TINYCLR_SSL_PRINTF("des_ede3_cbcm_encrypt decrypt error\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc_data[n]);
		TINYCLR_SSL_PRINTF("\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc_in[n]);
		TINYCLR_SSL_PRINTF("\n");
		err=1;
		}
#endif

	TINYCLR_SSL_PRINTF("Doing ecb\n");
	for (i=0; i<NUM_TESTS; i++)
		{
		DES_set_key_unchecked(&key_data[i],&ks);
		TINYCLR_SSL_MEMCPY(in,plain_data[i],8);
		TINYCLR_SSL_MEMSET(out,0,8);
		TINYCLR_SSL_MEMSET(outin,0,8);
		des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
		des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);

		if (TINYCLR_SSL_MEMCMP(out,cipher_data[i],8) != 0)
			{
			TINYCLR_SSL_PRINTF("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));
			err=1;
			}
		if (TINYCLR_SSL_MEMCMP(in,outin,8) != 0)
			{
			TINYCLR_SSL_PRINTF("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
				i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
			err=1;
			}
		}

#ifndef LIBDES_LIT
	TINYCLR_SSL_PRINTF("Doing ede ecb\n");
	for (i=0; i<(NUM_TESTS-2); 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);
		TINYCLR_SSL_MEMCPY(in,plain_data[i],8);
		TINYCLR_SSL_MEMSET(out,0,8);
		TINYCLR_SSL_MEMSET(outin,0,8);
		des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
		des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);

		if (TINYCLR_SSL_MEMCMP(out,cipher_ecb2[i],8) != 0)
			{
			TINYCLR_SSL_PRINTF("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));
			err=1;
			}
		if (TINYCLR_SSL_MEMCMP(in,outin,8) != 0)
			{
			TINYCLR_SSL_PRINTF("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
				i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
			err=1;
			}
		}
#endif

	TINYCLR_SSL_PRINTF("Doing cbc\n");
	if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	TINYCLR_SSL_MEMSET(cbc_out,0,40);
	TINYCLR_SSL_MEMSET(cbc_in,0,40);
	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	des_ncbc_encrypt(cbc_data,cbc_out,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
			 &iv3,DES_ENCRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_out,cbc_ok,32) != 0)
		{
		TINYCLR_SSL_PRINTF("cbc_encrypt encrypt error\n");
		err=1;
		}

	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	des_ncbc_encrypt(cbc_out,cbc_in,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
			 &iv3,DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_in,cbc_data,TINYCLR_SSL_STRLEN((char *)cbc_data)) != 0)
		{
		TINYCLR_SSL_PRINTF("cbc_encrypt decrypt error\n");
		err=1;
		}

#ifndef LIBDES_LIT
	TINYCLR_SSL_PRINTF("Doing desx cbc\n");
	if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	TINYCLR_SSL_MEMSET(cbc_out,0,40);
	TINYCLR_SSL_MEMSET(cbc_in,0,40);
	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	des_xcbc_encrypt(cbc_data,cbc_out,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
			 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_out,xcbc_ok,32) != 0)
		{
		TINYCLR_SSL_PRINTF("des_xcbc_encrypt encrypt error\n");
		err=1;
		}
	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	des_xcbc_encrypt(cbc_out,cbc_in,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
			 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_in,cbc_data,TINYCLR_SSL_STRLEN((char *)cbc_data)+1) != 0)
		{
		TINYCLR_SSL_PRINTF("des_xcbc_encrypt decrypt error\n");
		err=1;
		}
#endif

	TINYCLR_SSL_PRINTF("Doing ede cbc\n");
	if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	TINYCLR_SSL_MEMSET(cbc_out,0,40);
	TINYCLR_SSL_MEMSET(cbc_in,0,40);
	i=TINYCLR_SSL_STRLEN((char *)cbc_data)+1;
	/* i=((i+7)/8)*8; */
	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(cbc_out,cbc3_ok,
		(unsigned int)(TINYCLR_SSL_STRLEN((char *)cbc_data)+1+7)/8*8) != 0)
		{
		unsigned int n;

		TINYCLR_SSL_PRINTF("des_ede3_cbc_encrypt encrypt error\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc_out[n]);
		TINYCLR_SSL_PRINTF("\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc3_ok[n]);
		TINYCLR_SSL_PRINTF("\n");
		err=1;
		}

	TINYCLR_SSL_MEMCPY(iv3,cbc_iv,sizeof(cbc_iv));
	des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_in,cbc_data,TINYCLR_SSL_STRLEN((char *)cbc_data)+1) != 0)
		{
		unsigned int n;

		TINYCLR_SSL_PRINTF("des_ede3_cbc_encrypt decrypt error\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc_data[n]);
		TINYCLR_SSL_PRINTF("\n");
		for(n=0 ; n < i ; ++n)
		    TINYCLR_SSL_PRINTF(" %02x",cbc_in[n]);
		TINYCLR_SSL_PRINTF("\n");
		err=1;
		}

#ifndef LIBDES_LIT
	TINYCLR_SSL_PRINTF("Doing pcbc\n");
	if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
		{
		TINYCLR_SSL_PRINTF("Key error %d\n",j);
		err=1;
		}
	TINYCLR_SSL_MEMSET(cbc_out,0,40);
	TINYCLR_SSL_MEMSET(cbc_in,0,40);
	des_pcbc_encrypt(cbc_data,cbc_out,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
			 &cbc_iv,DES_ENCRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_out,pcbc_ok,32) != 0)
		{
		TINYCLR_SSL_PRINTF("pcbc_encrypt encrypt error\n");
		err=1;
		}
	des_pcbc_encrypt(cbc_out,cbc_in,TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,&cbc_iv,
			 DES_DECRYPT);
	if (TINYCLR_SSL_MEMCMP(cbc_in,cbc_data,TINYCLR_SSL_STRLEN((char *)cbc_data)+1) != 0)
		{
		TINYCLR_SSL_PRINTF("pcbc_encrypt decrypt error\n");
		err=1;
		}

	TINYCLR_SSL_PRINTF("Doing ");
	TINYCLR_SSL_PRINTF("cfb8 ");
	err+=cfb_test(8,cfb_cipher8);
	TINYCLR_SSL_PRINTF("cfb16 ");
	err+=cfb_test(16,cfb_cipher16);
	TINYCLR_SSL_PRINTF("cfb32 ");
	err+=cfb_test(32,cfb_cipher32);
	TINYCLR_SSL_PRINTF("cfb48 ");
	err+=cfb_test(48,cfb_cipher48);
	TINYCLR_SSL_PRINTF("cfb64 ");
	err+=cfb_test(64,cfb_cipher64);

	TINYCLR_SSL_PRINTF("cfb64() ");
	err+=cfb64_test(cfb_cipher64);

	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
		{
		TINYCLR_SSL_PRINTF("cfb_encrypt small encrypt error\n");
		err=1;
		}

	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(plain,cfb_buf2,sizeof(plain)) != 0)
		{
		TINYCLR_SSL_PRINTF("cfb_encrypt small decrypt error\n");
		err=1;
		}

	TINYCLR_SSL_PRINTF("ede_cfb64() ");
	err+=ede_cfb64_test(cfb_cipher64);

	TINYCLR_SSL_PRINTF("done\n");

	TINYCLR_SSL_PRINTF("Doing ofb\n");
	DES_set_key_checked(&ofb_key,&ks);
	TINYCLR_SSL_MEMCPY(ofb_tmp,ofb_iv,sizeof(ofb_iv));
	des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
	if (TINYCLR_SSL_MEMCMP(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
		{
		TINYCLR_SSL_PRINTF("ofb_encrypt encrypt error\n");
TINYCLR_SSL_PRINTF("%02X %02X %02X %02X %02X %02X %02X %02X\n",
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]);
TINYCLR_SSL_PRINTF("%02X %02X %02X %02X %02X %02X %02X %02X\n",
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]);
		err=1;
		}
	TINYCLR_SSL_MEMCPY(ofb_tmp,ofb_iv,sizeof(ofb_iv));
	des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
	if (TINYCLR_SSL_MEMCMP(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
		{
		TINYCLR_SSL_PRINTF("ofb_encrypt decrypt error\n");
TINYCLR_SSL_PRINTF("%02X %02X %02X %02X %02X %02X %02X %02X\n",
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]);
TINYCLR_SSL_PRINTF("%02X %02X %02X %02X %02X %02X %02X %02X\n",
plain[8+0], plain[8+1], plain[8+2], plain[8+3],
plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
		err=1;
		}

	TINYCLR_SSL_PRINTF("Doing ofb64\n");
	DES_set_key_checked(&ofb_key,&ks);
	TINYCLR_SSL_MEMCPY(ofb_tmp,ofb_iv,sizeof(ofb_iv));
	TINYCLR_SSL_MEMSET(ofb_buf1,0,sizeof(ofb_buf1));
	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
		{
		TINYCLR_SSL_PRINTF("ofb64_encrypt encrypt error\n");
		err=1;
		}
	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
		{
		TINYCLR_SSL_PRINTF("ofb64_encrypt decrypt error\n");
		err=1;
		}

	TINYCLR_SSL_PRINTF("Doing ede_ofb64\n");
	DES_set_key_checked(&ofb_key,&ks);
	TINYCLR_SSL_MEMCPY(ofb_tmp,ofb_iv,sizeof(ofb_iv));
	TINYCLR_SSL_MEMSET(ofb_buf1,0,sizeof(ofb_buf1));
	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
		{
		TINYCLR_SSL_PRINTF("ede_ofb64_encrypt encrypt error\n");
		err=1;
		}
	TINYCLR_SSL_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 (TINYCLR_SSL_MEMCMP(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
		{
		TINYCLR_SSL_PRINTF("ede_ofb64_encrypt decrypt error\n");
		err=1;
		}

	TINYCLR_SSL_PRINTF("Doing cbc_cksum\n");
	DES_set_key_checked(&cbc_key,&ks);
	cs=des_cbc_cksum(cbc_data,&cret,TINYCLR_SSL_STRLEN((char *)cbc_data),ks,&cbc_iv);
	if (cs != cbc_cksum_ret)
		{
		TINYCLR_SSL_PRINTF("bad return value (%08lX), should be %08lX\n",
			(unsigned long)cs,(unsigned long)cbc_cksum_ret);
		err=1;
		}
	if (TINYCLR_SSL_MEMCMP(cret,cbc_cksum_data,8) != 0)
		{
		TINYCLR_SSL_PRINTF("bad cbc_cksum block returned\n");
		err=1;
		}

	TINYCLR_SSL_PRINTF("Doing quad_cksum\n");
	cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
		(long)TINYCLR_SSL_STRLEN((char *)cbc_data),2,(des_cblock *)cbc_iv);
	if (cs != 0x70d7a63aL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, ret %08lx should be 70d7a63a\n",
			(unsigned long)cs);
		err=1;
		}
#ifdef _CRAY
	if (lqret[0].a != 0x327eba8dL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[0] %08lx is not %08lx\n",
			(unsigned long)lqret[0].a,0x327eba8dUL);
		err=1;
		}
	if (lqret[0].b != 0x201a49ccL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[1] %08lx is not %08lx\n",
			(unsigned long)lqret[0].b,0x201a49ccUL);
		err=1;
		}
	if (lqret[1].a != 0x70d7a63aL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[2] %08lx is not %08lx\n",
			(unsigned long)lqret[1].a,0x70d7a63aUL);
		err=1;
		}
	if (lqret[1].b != 0x501c2c26L)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[3] %08lx is not %08lx\n",
			(unsigned long)lqret[1].b,0x501c2c26UL);
		err=1;
		}
#else
	if (lqret[0] != 0x327eba8dL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[0] %08lx is not %08lx\n",
			(unsigned long)lqret[0],0x327eba8dUL);
		err=1;
		}
	if (lqret[1] != 0x201a49ccL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[1] %08lx is not %08lx\n",
			(unsigned long)lqret[1],0x201a49ccUL);
		err=1;
		}
	if (lqret[2] != 0x70d7a63aL)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[2] %08lx is not %08lx\n",
			(unsigned long)lqret[2],0x70d7a63aUL);
		err=1;
		}
	if (lqret[3] != 0x501c2c26L)
		{
		TINYCLR_SSL_PRINTF("quad_cksum error, out[3] %08lx is not %08lx\n",
			(unsigned long)lqret[3],0x501c2c26UL);
		err=1;
		}
#endif
#endif

	TINYCLR_SSL_PRINTF("input word alignment test");
	for (i=0; i<4; i++)
		{
		TINYCLR_SSL_PRINTF(" %d",i);
		des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
				 TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
				 &cbc_iv,DES_ENCRYPT);
		}
	TINYCLR_SSL_PRINTF("\noutput word alignment test");
	for (i=0; i<4; i++)
		{
		TINYCLR_SSL_PRINTF(" %d",i);
		des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
				 TINYCLR_SSL_STRLEN((char *)cbc_data)+1,ks,
				 &cbc_iv,DES_ENCRYPT);
		}
	TINYCLR_SSL_PRINTF("\n");
	TINYCLR_SSL_PRINTF("fast crypt test ");
	str=crypt("testing","ef");
	if (TINYCLR_SSL_STRCMP("efGnQx2725bI2",str) != 0)
		{
		TINYCLR_SSL_PRINTF("fast crypt error, %s should be efGnQx2725bI2\n",str);
		err=1;
		}
	str=crypt("bca76;23","yA");
	if (TINYCLR_SSL_STRCMP("yA1Rp/1hZXIJk",str) != 0)
		{
		TINYCLR_SSL_PRINTF("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
		err=1;
		}
#ifdef OPENSSL_SYS_NETWARE
    if (err) TINYCLR_SSL_PRINTF("ERROR: %d\n", err);
#endif
	TINYCLR_SSL_PRINTF("\n");
	return(err);
	}
Exemple #4
0
Code_t
ZMakeAuthentication(register ZNotice_t *notice,
		    char *buffer,
		    int buffer_len,
		    int *len)
{
#ifdef HAVE_KRB5
    return ZMakeZcodeAuthentication(notice, buffer, buffer_len, len/*?XXX*/);
#else
#ifdef HAVE_KRB4
    int result;
    KTEXT_ST authent;
    char *cstart, *cend;
    ZChecksum_t checksum;
    CREDENTIALS cred;
    C_Block *session;

    result = krb_mk_req(&authent, SERVER_SERVICE,
			SERVER_INSTANCE, __Zephyr_realm, 0);
    if (result != MK_AP_OK)
	return (result+krb_err_base);
    result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
			  __Zephyr_realm, &cred);
    if (result != KSUCCESS)
	return (result+krb_err_base);

    session = (C_Block *)cred.session;

    notice->z_auth = 1;
    notice->z_authent_len = authent.length;
    notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3);
    /* zero length authent is an error, so malloc(0) is not a problem */
    if (!notice->z_ascii_authent)
	return (ENOMEM);
    if ((result = ZMakeAscii(notice->z_ascii_authent,
			     authent.length*3,
			     authent.dat,
			     authent.length)) != ZERR_NONE) {
	free(notice->z_ascii_authent);
	return (result);
    }
    result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
			       &cend);
    free(notice->z_ascii_authent);
    notice->z_authent_len = 0;
    if (result)
	return(result);

    /* Compute a checksum over the header and message. */
    checksum = des_quad_cksum((unsigned char *)buffer, NULL, cstart - buffer, 0, session);
    checksum ^= des_quad_cksum((unsigned char *)cend, NULL, buffer + *len - cend, 0,
			       session);
    checksum ^= des_quad_cksum((unsigned char *)notice->z_message, NULL, notice->z_message_len,
			       0, session);
    notice->z_checksum = checksum;
    ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum);

    return (ZERR_NONE);
#else
    notice->z_checksum = 0;
    notice->z_auth = 1;
    notice->z_authent_len = 0;
    notice->z_ascii_authent = "";
    return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));
#endif
#endif
}