Exemplo n.º 1
0
static inline err_status_t
crypto_kernel_do_load_cipher_type(cipher_type_t *new_ct, cipher_type_id_t id,
				  int replace) {
  kernel_cipher_type_t *ctype, *new_ctype;
  err_status_t status;

  /* defensive coding */
  if (new_ct == NULL)
    return err_status_bad_param;

  if (new_ct->id != id)
    return err_status_bad_param;

  /* check cipher type by running self-test */
  status = cipher_type_self_test(new_ct);
  if (status) {
    return status;
  }

  /* walk down list, checking if this type is in the list already  */
  ctype = crypto_kernel.cipher_type_list;
  while (ctype != NULL) {
    if (id == ctype->id) {
      if (!replace)
	return err_status_bad_param;
      status = cipher_type_test(new_ct, ctype->cipher_type->test_data);
      if (status)
	return status;
      new_ctype = ctype;
      break;
    }
    else if (new_ct == ctype->cipher_type)
      return err_status_bad_param;    
    ctype = ctype->next;
  }

  /* if not found, put new_ct at the head of the list */
  if (ctype == NULL) {
  /* allocate memory */
    new_ctype = (kernel_cipher_type_t *) crypto_alloc(sizeof(kernel_cipher_type_t));
    if (new_ctype == NULL)
      return err_status_alloc_fail;
    new_ctype->next = crypto_kernel.cipher_type_list;

    /* set head of list to new cipher type */
    crypto_kernel.cipher_type_list = new_ctype;    
  }
    
  /* set fields */
  new_ctype->cipher_type = new_ct;
  new_ctype->id = id;

  /* load debug module, if there is one present */
  if (new_ct->debug != NULL)
    crypto_kernel_load_debug_module(new_ct->debug);
  /* we could check for errors here */

  return err_status_ok;
}
Exemplo n.º 2
0
err_status_t
cipher_type_self_test(const cipher_type_t *ct) {
  return cipher_type_test(ct, ct->test_data);
}