Ejemplo n.º 1
0
int
main (int argc, char *argv[])
{
    cipher_t *c = NULL;
    err_status_t status;
    unsigned char test_key[32] = {
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
        0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    };
    int q;
    unsigned do_timing_test = 0;
    unsigned do_validation = 0;
    unsigned do_array_timing_test = 0;

    /* process input arguments */
    while (1) {
        q = getopt(argc, argv, "tva");
        if (q == -1) {
            break;
        }
        switch (q) {
        case 't':
            do_timing_test = 1;
            break;
        case 'v':
            do_validation = 1;
            break;
        case 'a':
            do_array_timing_test = 1;
            break;
        default:
            usage(argv[0]);
        }
    }

    printf("cipher test driver\n"
           "David A. McGrew\n"
           "Cisco Systems, Inc.\n");

    if (!do_validation && !do_timing_test && !do_array_timing_test) {
        usage(argv[0]);
    }

    /* arry timing (cache thrash) test */
    if (do_array_timing_test) {
        int max_num_cipher = 1 << 16; /* number of ciphers in cipher_array */
        int num_cipher;

        for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
            cipher_driver_test_array_throughput(&null_cipher, 0, num_cipher);
        }

        for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
            cipher_driver_test_array_throughput(&aes_icm_openssl, 30, num_cipher);
        }

        for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
            cipher_driver_test_array_throughput(&aes_icm_192_openssl, 38, num_cipher);
        }

        for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
            cipher_driver_test_array_throughput(&aes_icm_256_openssl, 46, num_cipher);
        }

	for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8) {
	    cipher_driver_test_array_throughput(&aes_gcm_128_8_openssl, 16, num_cipher); 
	}
    }

    if (do_validation) {
        cipher_driver_self_test(&null_cipher);
        cipher_driver_self_test(&aes_icm_openssl);
        cipher_driver_self_test(&aes_icm_192_openssl);
        cipher_driver_self_test(&aes_icm_256_openssl);
        cipher_driver_self_test(&aes_gcm_128_8_openssl);
    }

    /* do timing and/or buffer_test on null_cipher */
    status = cipher_type_alloc(&null_cipher, &c, 0);
    check_status(status);

    status = cipher_init(c, NULL);
    check_status(status);

    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }
    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);


    /* run the throughput test on the aes_icm_openssl cipher */
    status = cipher_type_alloc(&aes_icm_openssl, &c, 30);
    if (status) {
        fprintf(stderr, "error: can't allocate cipher\n");
        exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }

    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);

    /* run the throughput test on the aes_icm_192_openssl cipher */
    status = cipher_type_alloc(&aes_icm_192_openssl, &c, 38);
    if (status) {
        fprintf(stderr, "error: can't allocate cipher\n");
        exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }

    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);

    /* run the throughput test on the aes_icm_256_openssl cipher */
    status = cipher_type_alloc(&aes_icm_256_openssl, &c, 46);
    if (status) {
        fprintf(stderr, "error: can't allocate cipher\n");
        exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }

    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);

    /* run the throughput test on the aes_gcm_128_8_openssl cipher */
    status = cipher_type_alloc(&aes_gcm_128_8_openssl, &c, 16);  
    if (status) {
	fprintf(stderr, "error: can't allocate cipher\n");
	exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
	cipher_driver_test_throughput(c);
    }
    
    if (do_validation) {
	status = cipher_driver_test_buffering(c);
	check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);
    
    return 0;
}
Ejemplo n.º 2
0
int
main(int argc, char *argv[]) {
  cipher_t *c = NULL;
  err_status_t status;
  unsigned char test_key[48] = {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  };
  int q;
  unsigned do_timing_test = 0;
  unsigned do_validation = 0;
  unsigned do_array_timing_test = 0;

  /* process input arguments */
  while (1) {
    q = getopt(argc, argv, "tva");
    if (q == -1) 
      break;
    switch (q) {
    case 't':
      do_timing_test = 1;
      break;
    case 'v':
      do_validation = 1;
      break;
    case 'a':
      do_array_timing_test = 1;
      break;
    default:
      usage(argv[0]);
    }    
  }
   
  printf("cipher test driver\n"
	 "David A. McGrew\n"
	 "Cisco Systems, Inc.\n");

  if (!do_validation && !do_timing_test && !do_array_timing_test)
    usage(argv[0]);

   /* arry timing (cache thrash) test */
  if (do_array_timing_test) {
    int max_num_cipher = 1 << 16;   /* number of ciphers in cipher_array */
    int num_cipher;
    
    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&null_cipher, 0, num_cipher); 

    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_icm, 30, num_cipher); 

#ifndef OPENSSL
    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_icm, 46, num_cipher); 

    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_cbc, 16, num_cipher); 
 
    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_cbc, 32, num_cipher); 
#else
#ifndef BORINGSSL
    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_icm_192, 38, num_cipher); 
#endif

    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8)
      cipher_driver_test_array_throughput(&aes_icm_256, 46, num_cipher); 

    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8) {
	cipher_driver_test_array_throughput(&aes_gcm_128_openssl, AES_128_GCM_KEYSIZE_WSALT, num_cipher);         
    }

    for (num_cipher=1; num_cipher < max_num_cipher; num_cipher *=8) {
	cipher_driver_test_array_throughput(&aes_gcm_256_openssl, AES_256_GCM_KEYSIZE_WSALT, num_cipher);         
    }
#endif
  }

  if (do_validation) {
    cipher_driver_self_test(&null_cipher);
    cipher_driver_self_test(&aes_icm);
#ifndef OPENSSL
    cipher_driver_self_test(&aes_cbc);
#else
#ifndef BORINGSSL
    cipher_driver_self_test(&aes_icm_192);
#endif
    cipher_driver_self_test(&aes_icm_256);
    cipher_driver_self_test(&aes_gcm_128_openssl);
    cipher_driver_self_test(&aes_gcm_256_openssl);
#endif
  }

  /* do timing and/or buffer_test on null_cipher */
  status = cipher_type_alloc(&null_cipher, &c, 0, 0); 
  check_status(status);

  status = cipher_init(c, NULL);
  check_status(status);

  if (do_timing_test) 
    cipher_driver_test_throughput(c);
  if (do_validation) {
    status = cipher_driver_test_buffering(c);
    check_status(status);
  }
  status = cipher_dealloc(c);
  check_status(status);
  

  /* run the throughput test on the aes_icm cipher (128-bit key) */
    status = cipher_type_alloc(&aes_icm, &c, 30, 0);  
    if (status) {
      fprintf(stderr, "error: can't allocate cipher\n");
      exit(status);
    }

    status = cipher_init(c, test_key);
    check_status(status);

    if (do_timing_test)
      cipher_driver_test_throughput(c);
    
    if (do_validation) {
      status = cipher_driver_test_buffering(c);
      check_status(status);
    }
    
    status = cipher_dealloc(c);
    check_status(status);

  /* repeat the tests with 256-bit keys */
#ifndef OPENSSL
    status = cipher_type_alloc(&aes_icm, &c, 46, 0);  
#else
    status = cipher_type_alloc(&aes_icm_256, &c, 46, 0);  
#endif
    if (status) {
      fprintf(stderr, "error: can't allocate cipher\n");
      exit(status);
    }

    status = cipher_init(c, test_key);
    check_status(status);

    if (do_timing_test)
      cipher_driver_test_throughput(c);
    
    if (do_validation) {
      status = cipher_driver_test_buffering(c);
      check_status(status);
    }
    
    status = cipher_dealloc(c);
    check_status(status);

#ifdef OPENSSL
    /* run the throughput test on the aes_gcm_128_openssl cipher */
    status = cipher_type_alloc(&aes_gcm_128_openssl, &c, AES_128_GCM_KEYSIZE_WSALT, 8);
    if (status) {
        fprintf(stderr, "error: can't allocate GCM 128 cipher\n");
        exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }

    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);

    /* run the throughput test on the aes_gcm_256_openssl cipher */
    status = cipher_type_alloc(&aes_gcm_256_openssl, &c, AES_256_GCM_KEYSIZE_WSALT, 16);
    if (status) {
        fprintf(stderr, "error: can't allocate GCM 256 cipher\n");
        exit(status);
    }
    status = cipher_init(c, test_key);
    check_status(status);
    if (do_timing_test) {
        cipher_driver_test_throughput(c);
    }

    if (do_validation) {
        status = cipher_driver_test_buffering(c);
        check_status(status);
    }
    status = cipher_dealloc(c);
    check_status(status);
#endif 

    return 0;
}