예제 #1
0
파일: casttest.c 프로젝트: Vonage/openssl
static int cast_test_iterations(void)
{
    long l;
    int testresult = 1;
    CAST_KEY key, key_b;
    unsigned char out_a[16], out_b[16];

    memcpy(out_a, in_a, sizeof(in_a));
    memcpy(out_b, in_b, sizeof(in_b));

    for (l = 0; l < 1000000L; l++) {
        CAST_set_key(&key_b, 16, out_b);
        CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT);
        CAST_ecb_encrypt(&(out_a[8]), &(out_a[8]), &key_b, CAST_ENCRYPT);
        CAST_set_key(&key, 16, out_a);
        CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT);
        CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT);
    }

    if (!TEST_mem_eq(out_a, sizeof(c_a), c_a, sizeof(c_a))
            || !TEST_mem_eq(out_b, sizeof(c_b), c_b, sizeof(c_b)))
        testresult = 0;

    return testresult;
}
예제 #2
0
static void run_crypto_cast128(uint8_t *output,
                               const uint8_t *input, unsigned size)
{
    CAST_KEY cast;
    unsigned i;

    CAST_set_key(&cast, 16, hardcoded_key);
    for (i = 0; i < size; i += 8)
        CAST_ecb_encrypt(input + i, output + i, &cast, 1);
}
예제 #3
0
static int
ossl_cast_ecb_decrypt(PX_Cipher *c, const uint8 *data, unsigned dlen, uint8 *res)
{
	unsigned	bs = gen_ossl_block_size(c);
	ossldata   *od = c->ptr;
	const uint8 *end = data + dlen - bs;

	for (; data <= end; data += bs, res += bs)
		CAST_ecb_encrypt(data, res, &od->u.cast_key, CAST_DECRYPT);
	return 0;
}
예제 #4
0
파일: casttest.c 프로젝트: Vonage/openssl
static int cast_test_vector(int z)
{
    int testresult = 1;
    CAST_KEY key;
    unsigned char out[80];

    CAST_set_key(&key, k_len[z], k);
    CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
    if (!TEST_mem_eq(out, sizeof(c[z]), c[z], sizeof(c[z]))) {
        TEST_info("CAST_ENCRYPT iteration %d failed (len=%d)", z, k_len[z]);
        testresult = 0;
    }

    CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
    if (!TEST_mem_eq(out, sizeof(in), in, sizeof(in))) {
        TEST_info("CAST_DECRYPT iteration %d failed (len=%d)", z, k_len[z]);
        testresult = 0;
    }
    return testresult;
}
예제 #5
0
파일: symmetric.c 프로젝트: Henauxg/minix
static void 
cast5_block_decrypt(pgp_crypt_t *crypt, void *out, const void *in)
{
	CAST_ecb_encrypt(in, out, crypt->encrypt_key, CAST_DECRYPT);
}
예제 #6
0
int main(int argc, char *argv[])
    {
#ifdef FULL_TEST
    long l;
    CAST_KEY key_b;
#endif
    int i,z,err=0;
    CAST_KEY key;

    for (z=0; z<3; z++)
	{
	CAST_set_key(&key,k_len[z],k);

	CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
	if (memcmp(out,&(c[z][0]),8) != 0)
	    {
	    printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
	    printf("got     :");
	    for (i=0; i<8; i++)
		printf("%02X ",out[i]);
	    printf("\n");
	    printf("expected:");
	    for (i=0; i<8; i++)
		printf("%02X ",c[z][i]);
	    err=20;
	    printf("\n");
	    }

	CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
	if (memcmp(out,in,8) != 0)
	    {
	    printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
	    printf("got     :");
	    for (i=0; i<8; i++)
		printf("%02X ",out[i]);
	    printf("\n");
	    printf("expected:");
	    for (i=0; i<8; i++)
		printf("%02X ",in[i]);
	    printf("\n");
	    err=3;
	    }
	}
    if (err == 0)
	printf("ecb cast5 ok\n");

#ifdef FULL_TEST
      {
      unsigned char out_a[16],out_b[16];
      static char *hex="0123456789ABCDEF";
      
      printf("This test will take some time....");
      fflush(stdout);
      memcpy(out_a,in_a,sizeof(in_a));
      memcpy(out_b,in_b,sizeof(in_b));
      i=1;

      for (l=0; l<1000000L; l++)
	  {
	  CAST_set_key(&key_b,16,out_b);
	  CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
	  CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
	  CAST_set_key(&key,16,out_a);
	  CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
	  CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
	  if ((l & 0xffff) == 0xffff)
	      {
	      printf("%c",hex[i&0x0f]);
	      fflush(stdout);
	      i++;
	      }
	  }

      if (	(memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
		(memcmp(out_b,c_b,sizeof(c_b)) != 0))
	  {
	  printf("\n");
	  printf("Error\n");

	  printf("A out =");
	  for (i=0; i<16; i++) printf("%02X ",out_a[i]);
	  printf("\nactual=");
	  for (i=0; i<16; i++) printf("%02X ",c_a[i]);
	  printf("\n");

	  printf("B out =");
	  for (i=0; i<16; i++) printf("%02X ",out_b[i]);
	  printf("\nactual=");
	  for (i=0; i<16; i++) printf("%02X ",c_b[i]);
	  printf("\n");
	  }
      else
	  printf(" ok\n");
      }
#endif

    exit(err);
    }
예제 #7
0
static void 
cast5_block_encrypt(__ops_crypt_t *crypt, void *out, const void *in)
{
	CAST_ecb_encrypt(in, out, crypt->encrypt_key, CAST_ENCRYPT);
}