Пример #1
0
int main (void)
{
  if (&a.c - &a.a != 32)
    return 1;
  if (sizeof (a) != 36)
    return 2;
  if (sizeof (a4) != 4 * 36)
    return 3;
  if (sizeof (b) != 2 * 4 + 36)
    return 4;
  if (__alignof__ (b.e) != 4)
    return 5;
  if (&c.i - &c.g != 12)
    return 6;
  if (sizeof (c) != 16)
    return 7;
  if (sizeof (c4) != 4 * 16)
    return 8;
  if (sizeof (d) != 2 * 4 + 16)
    return 9;
  if (__alignof__ (d.k) != 4)
    return 10;
  if (&e.o - &e.m != 24)
    return 11;
  if (sizeof (e) != 28)
    return 12;
  if (sizeof (e4) != 4 * 28)
    return 13;
  if (sizeof (f) != 2 * 4 + 28)
    return 14;
  if (__alignof__ (f.q) != 4)
    return 15;
  return 0;
}
Пример #2
0
int
main ()
{
  if (__alignof__ (x4) < 4)
    abort ();

  if (__alignof__ (x8) < 8)
    abort ();

  if (__alignof__ (y8) < 8)
    abort ();

  if (__alignof__ (z8) < 8)
    abort ();

  if (__alignof__ (x16) < 16)
    abort ();

  if (__alignof__ (x32) < 32)
    abort ();

  if (__alignof__ (x64) < 64)
    abort ();

  if (__alignof__ (x128) < 128)
    abort ();

  if (__alignof__ (y128) < 128)
    abort ();

  if (__alignof__ (z128) < 128)
    abort (); 

  return 0;
}
Пример #3
0
void foo (int *r, bar t)
{
  // doing alignof on a bit-field should be illegal
  __alignof__ (t.bit);// ERROR - .*

  // both of these (a regular ref and an INDIRECT_REF) should work
  __alignof__ (r);
  __alignof__ (*r);
}
Пример #4
0
int main (void) {
  printf ("+++Array double:\n");
  printf ("size=%d,align=%d,5th-elem-offset=%d,5th-elem-align=%d\n",
          sizeof (a), __alignof__ (a),
          (char *) &a[5] - (char *) a, __alignof__ (a[5]));
  printf ("size=%d,align=%d,5th-elem-offset=%d,5th-elem-align=%d\n",
          sizeof (e), __alignof__ (e),
          (char *) &e[5] - (char *) a, __alignof__ (e[5]));
  return 0;
}
Пример #5
0
 void Baz (I *x)
 {
   Foo (sizeof (I));
   Foo (sizeof (x));
   Foo (__alignof__ (I));
   Foo (__alignof__ (x));
   Foo (x->~I ()); // { dg-error "" }
   //    Foo (typeid (I));
   Foo (delete x); // { dg-error "" }
   Foo (delete[] x); // { dg-error "" }
   Foo (throw x); // { dg-error "" }
 }
Пример #6
0
void
foo (void)
{
  aligned j;
  void bar ()
    {
      aligned i;
      if (check_int (&i, __alignof__(i)) != i)
	abort ();
      if (check_int (&j, __alignof__(j)) != j)
	abort ();
      j = -20;
    }
Пример #7
0
ExLockSync::ExLockSync()
{
#ifdef DEBUG
    m_lockOwner = 0;
#endif

    CASSERT( sizeof( m_data ) == sizeof( pthread_mutex_t ) );
    CASSERT( __alignof__( Data ) == __alignof__( pthread_mutex_t ) );

    if( int err = pthread_mutex_init( pmtx( &m_data ), 0 ) )
    {
        throwSystemError( err, "newlock" );
    }
}
Пример #8
0
void
check (int *i)
{
  *i = 20;
  if ((((ptrdiff_t) i) & (__alignof__(aligned) - 1)) != 0)
    abort ();
}
int main(void)
{
  if (sizeof (foo) != 2 || __alignof__ (foo) != 1)
    abort ();

  exit (0);
}
Пример #10
0
int main(){

	size_t saltlen = 16;
	size_t outlen  = 32;
	unsigned int t_cost = (unsigned int)pow(2,13);
	unsigned int m_cost = (unsigned int)pow(2,15);
	int i;

	char *passwd="password";
	uint8_t res[outlen] 
	__attribute__((__aligned__(__alignof__(uint32_t))));
	
	srand(time(NULL));
	rand();
	uint32_t salt[saltlen >> 2];
	for (i=0;i<(saltlen >> 2);i++)
		salt[i] = rand();

	clock_t start = -clock();

	PHS((void *)res,outlen,(void *)passwd,strlen(passwd),(void *)salt,saltlen,t_cost,m_cost);

	start += clock();
	
	float sec = (float)start/CLOCKS_PER_SEC;
	printf("%.3f secs,%.3f passwords\n",sec,(float)(1/sec));
	
	return 0;
}
Пример #11
0
void
fn1 (int i, int *p)
{
l:
  _Cilk_spawn (void); /* { dg-error "expected expression" } */
  _Cilk_spawn (char []); /* { dg-error "expected expression" } */
  _Cilk_spawn (int *); /* { dg-error "expected expression" } */
  _Cilk_spawn (int) 1; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn ({}); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn ++i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn i++; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn --i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn i--; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn &i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn +i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn -i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn ~i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn !i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn *p; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn &&l; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn sizeof (i); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn sizeof (short); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __alignof__ (i); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __alignof__ (short); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __extension__ i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __func__; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn p[0]; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __real__ i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn __imag__ i; /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn !foo (); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn ~foo (); /* { dg-error "only function calls can be spawned" } */
  _Cilk_spawn (unsigned) foo (); /* { dg-error "only function calls can be spawned" } */
}
Пример #12
0
void
fn2 (int i, int *p)
{
l:
  _Cilk_spawn _Cilk_spawn (void); /* { dg-error "consecutive|expected expression" } */
  _Cilk_spawn _Cilk_spawn (char []); /* { dg-error "consecutive|expected expression" } */
  _Cilk_spawn _Cilk_spawn (int *); /* { dg-error "consecutive|expected expression" } */
  _Cilk_spawn _Cilk_spawn (int) 1; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn ({}); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn ++i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn i++; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn --i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn i--; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn &i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn +i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn -i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn ~i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn !i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn *p; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn &&l; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn sizeof (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn sizeof (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __alignof__ (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __alignof__ (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __extension__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __func__; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn p[0]; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __real__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn __imag__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn !foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn ~foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
  _Cilk_spawn _Cilk_spawn (unsigned) foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
}
Пример #13
0
void check_placement_cookie (int i)
{
  p = malloc (sizeof (T) * 11 + 100);
  void* a = new (p) T[11];
  size_t x;

  // Compute the cookie location manually.
#ifdef __ARM_EABI__
  x = 8;
#else
  x = __alignof__ (T);
  if (x < sizeof (size_t))
    x = sizeof (size_t);
#endif
  if ((char *) a - x != (char *) p)
    exit (i);

  // Check the cookie value.
  size_t *sp = ((size_t *) a) - 1;
  if (*sp != 11)
    exit (i);

#ifdef __ARM_EABI__
  sp = ((size_t *) a) - 2;
  if (*sp != sizeof (T))
    exit (i);
#endif
}
Пример #14
0
int foo(int n)
{
  int (*t)[n];
  i = 0;
  int j = 0;
  char b[1][n+3];			/* Variable length array.  */
  int d[3][n];				/* Variable length array.  */
  sizeof (b[i++ + sizeof(j++)]);	/* Outer sizeof is evaluated for vla, but not the inner one.  */
  if (i != 1 || j != 0)
    return 1;
  __typeof__(b[i++]) c1;		/* typeof is evauluated when given a vm */
  if (i != 2)
    return 1;
  __typeof__(t + (i++,0)) c2;		/* typeof is evauluated when given a vm */
  if (i != 3)
    return 1;
  __typeof__(i + (i++,0)) c3;		/* typeof is not evauluated when not given a vm */
  if (i != 3)
    return 1;
  sizeof (d[i++]);			/* sizeof is evaluated for vla.  */
  if (i != 4)
    return 1;
  __alignof__(__typeof__(t + (i++,0)));	/* typeof is not evauluated when given a vm inside alignof*/
  if (i != 4)
    return 1;
  sizeof(__typeof__(t + (i++,0)));	/* typeof is not evauluated when given a vm inside sizeof*/
  if (i != 4)
    return 1;
  return 0;
}
Пример #15
0
Файл: iobuf.c Проект: 42wim/ipxe
/**
 * Concatenate I/O buffers into a single buffer
 *
 * @v list	List of I/O buffers
 * @ret iobuf	Concatenated I/O buffer, or NULL on allocation failure
 *
 * After a successful concatenation, the list will be empty.
 */
struct io_buffer * iob_concatenate ( struct list_head *list ) {
	struct io_buffer *iobuf;
	struct io_buffer *tmp;
	struct io_buffer *concatenated;
	size_t len = 0;

	/* If the list contains only a single entry, avoid an
	 * unnecessary additional allocation.
	 */
	if ( list_is_singular ( list ) ) {
		iobuf = list_first_entry ( list, struct io_buffer, list );
		INIT_LIST_HEAD ( list );
		return iobuf;
	}

	/* Calculate total length */
	list_for_each_entry ( iobuf, list, list )
		len += iob_len ( iobuf );

	/* Allocate new I/O buffer */
	concatenated = alloc_iob_raw ( len, __alignof__ ( *iobuf ), 0 );
	if ( ! concatenated )
		return NULL;

	/* Move data to new I/O buffer */
	list_for_each_entry_safe ( iobuf, tmp, list, list ) {
		list_del ( &iobuf->list );
		memcpy ( iob_put ( concatenated, iob_len ( iobuf ) ),
			 iobuf->data, iob_len ( iobuf ) );
		free_iob ( iobuf );
	}
Пример #16
0
void
foo (void *frame, uword_t error_code)
{
  aligned j;
  if (check_int (frame, &j, __alignof__(j)))
    __builtin_abort ();
}
Пример #17
0
static struct crypto_instance *seqiv_alloc(struct rtattr **tb)
{
	struct crypto_attr_type *algt;
	struct crypto_instance *inst;
	int err;

	algt = crypto_get_attr_type(tb);
	if (IS_ERR(algt))
		return ERR_CAST(algt);

	err = crypto_get_default_rng();
	if (err)
		return ERR_PTR(err);

	if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
		inst = seqiv_ablkcipher_alloc(tb);
	else
		inst = seqiv_aead_alloc(tb);

	if (IS_ERR(inst))
		goto put_rng;

	inst->alg.cra_alignmask |= __alignof__(u32) - 1;
	inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx);

out:
	return inst;

put_rng:
	crypto_put_default_rng();
	goto out;
}
Пример #18
0
void test4() {
  t1 = sizeof(void);
  t2 = __alignof__(void);
  
  t1 = sizeof(test4());
  t2 = __alignof__(test4());
}
Пример #19
0
int
main ()
{
 A aa;
 B bb;

 static_assert (sizeof (a) == 4, "sizeof (a) should be 4");
 static_assert (sizeof (b) == 16, "sizeof (b) should be 16");
 static_assert (sizeof (aa) == 4, "sizeof (aa) should be 4");
 static_assert (sizeof (bb) == 16, "sizeof (bb) should be 16");

 static_assert (__alignof__  (a) == 16, "alignof (a) should be 16");
 static_assert (__alignof__  (b) == 16, "alignof (b) should be 16");
 static_assert (__alignof__  (aa) == 4, "alignof (aa) should be 4");
 static_assert (__alignof__  (bb) == 16, "alignof (bb) should be 16");
}
Пример #20
0
static int
xencomm_ctxt_init(const void *handle, struct xencomm_ctxt *ctxt)
{
    struct page_info *page;
    struct xencomm_desc *desc;
    int ret;

    /* Avoid unaligned access. */
    if ( ((unsigned long)handle % __alignof__(*desc)) != 0 )
        return -EINVAL;
    if ( xencomm_desc_cross_page_boundary((unsigned long)handle) )
        return -EINVAL;

    /* First we need to access the descriptor. */
    ret = xencomm_get_page((unsigned long)handle, &page);
    if ( ret )
        return ret;

    desc = xencomm_vaddr((unsigned long)handle, page);
    if ( desc->magic != XENCOMM_MAGIC )
    {
        printk("%s: error: %p magic was 0x%x\n", __func__, desc, desc->magic);
        put_page(page);
        return -EINVAL;
    }

    /* Copy before use: It is possible for a guest to modify concurrently. */
    ctxt->nr_addrs = desc->nr_addrs;
    ctxt->desc_in_paddr = (struct xencomm_desc*)handle;
    ctxt->page = page;
    ctxt->address = &desc->address[0];
    return 0;
}
Пример #21
0
int main(){

  typedef struct { float f[4]; } __attribute__ ((aligned (16))) __m128;

  printf("%d\n", __alignof__(__m128));

  return 0;
}
Пример #22
0
void
foo (void)
{
  aligned i;

  if (check_int (&i,  __alignof__(i)) != i)
    abort ();
}
foo ()
{
  int __attribute__ ((aligned(64))) a=1;
  if (check_int (&a,  __alignof__(a)) != a)
    abort ();
  ALTER_REGS();
  throw a;
}
Пример #24
0
void
non_evaluated (void)
{
  s = sizeof (f + 1.0);             /* { dg-bogus "implicit" } */
  s = __alignof__ (f + 1.0);        /* { dg-bogus "implicit" } */
  d = (__typeof__(f + 1.0))f;       /* { dg-bogus "implicit" } */
  s = sizeof (i ? f : d);           /* { dg-bogus "implicit" } */
}
Пример #25
0
void
subsegs_begin ()
{
  /* Check table(s) seg_name[], seg_N_TYPE[] is in correct order */
#if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
  know (SEG_ABSOLUTE == 0);
  know (SEG_TEXT == 1);
  know (SEG_DATA == 2);
  know (SEG_BSS == 3);
  know (SEG_UNKNOWN == 4);
  know (SEG_GOOF == 5);
  know (SEG_EXPR == 6);
  know (SEG_DEBUG == 7);
  know (SEG_NTV == 8);
  know (SEG_PTV == 9);
  know (SEG_REGISTER == 10);
  know (SEG_MAXIMUM_ORDINAL == SEG_REGISTER);
#endif

  obstack_begin (&frchains, chunksize);
#if __GNUC__ >= 2
  obstack_alignment_mask (&frchains) = __alignof__ (frchainS) - 1;
#endif

  frchain_root = NULL;
  frchain_now = NULL;		/* Warn new_subseg() that we are booting.  */

  frag_now = &dummy_frag;

#ifndef BFD_ASSEMBLER
  now_subseg = 42;		/* Lie for 1st call to subseg_new.  */
#ifdef MANY_SEGMENTS
  {
    int i;
    for (i = SEG_E0; i < SEG_UNKNOWN; i++)
      {
	subseg_set (i, 0);
	segment_info[i].frchainP = frchain_now;
      }
  }
#else
  subseg_set (SEG_DATA, 0);	/* .data 0 */
  data0_frchainP = frchain_now;

  subseg_set (SEG_BSS, 0);
  bss0_frchainP = frchain_now;

#endif /* ! MANY_SEGMENTS */
#endif /* ! BFD_ASSEMBLER */

  absolute_frchain.frch_seg = absolute_section;
  absolute_frchain.frch_subseg = 0;
#ifdef BFD_ASSEMBLER
  absolute_frchain.fix_root = absolute_frchain.fix_tail = 0;
#endif
  absolute_frchain.frch_frag_now = &zero_address_frag;
  absolute_frchain.frch_root = absolute_frchain.frch_last = &zero_address_frag;
}
Пример #26
0
int __init early_init_dt_scan_recoverable_ranges(unsigned long node,
				   const char *uname, int depth, void *data)
{
	int i, psize, size;
	const __be32 *prop;

	if (depth != 1 || strcmp(uname, "ibm,opal") != 0)
		return 0;

	prop = of_get_flat_dt_prop(node, "mcheck-recoverable-ranges", &psize);

	if (!prop)
		return 1;

	pr_debug("Found machine check recoverable ranges.\n");

	/*
	 * Calculate number of available entries.
	 *
	 * Each recoverable address range entry is (start address, len,
	 * recovery address), 2 cells each for start and recovery address,
	 * 1 cell for len, totalling 5 cells per entry.
	 */
	mc_recoverable_range_len = psize / (sizeof(*prop) * 5);

	/* Sanity check */
	if (!mc_recoverable_range_len)
		return 1;

	/* Size required to hold all the entries. */
	size = mc_recoverable_range_len *
			sizeof(struct mcheck_recoverable_range);

	/*
	 * Allocate a buffer to hold the MC recoverable ranges. We would be
	 * accessing them in real mode, hence it needs to be within
	 * RMO region.
	 */
	mc_recoverable_range =__va(memblock_alloc_base(size, __alignof__(u64),
							ppc64_rma_size));
	memset(mc_recoverable_range, 0, size);

	for (i = 0; i < mc_recoverable_range_len; i++) {
		mc_recoverable_range[i].start_addr =
					of_read_number(prop + (i * 5) + 0, 2);
		mc_recoverable_range[i].end_addr =
					mc_recoverable_range[i].start_addr +
					of_read_number(prop + (i * 5) + 2, 1);
		mc_recoverable_range[i].recover_addr =
					of_read_number(prop + (i * 5) + 3, 2);

		pr_debug("Machine check recoverable range: %llx..%llx: %llx\n",
				mc_recoverable_range[i].start_addr,
				mc_recoverable_range[i].end_addr,
				mc_recoverable_range[i].recover_addr);
	}
	return 1;
}
Пример #27
0
Файл: iobuf.c Проект: 42wim/ipxe
/**
 * Allocate I/O buffer with specified alignment and offset
 *
 * @v len	Required length of buffer
 * @v align	Physical alignment
 * @v offset	Offset from physical alignment
 * @ret iobuf	I/O buffer, or NULL if none available
 *
 * @c align will be rounded up to the nearest power of two.
 */
struct io_buffer * alloc_iob_raw ( size_t len, size_t align, size_t offset ) {
	struct io_buffer *iobuf;
	void *data;

	/* Align buffer length to ensure that struct io_buffer is aligned */
	len = ( len + __alignof__ ( *iobuf ) - 1 ) &
		~( __alignof__ ( *iobuf ) - 1 );

	/* Round up alignment to the nearest power of two */
	align = ( 1 << fls ( align - 1 ) );

	/* Allocate buffer plus descriptor as a single unit, unless
	 * doing so will push the total size over the alignment
	 * boundary.
	 */
	if ( ( len + sizeof ( *iobuf ) ) <= align ) {

		/* Allocate memory for buffer plus descriptor */
		data = malloc_dma_offset ( len + sizeof ( *iobuf ), align,
					   offset );
		if ( ! data )
			return NULL;
		iobuf = ( data + len );

	} else {

		/* Allocate memory for buffer */
		data = malloc_dma_offset ( len, align, offset );
		if ( ! data )
			return NULL;

		/* Allocate memory for descriptor */
		iobuf = malloc ( sizeof ( *iobuf ) );
		if ( ! iobuf ) {
			free_dma ( data, len );
			return NULL;
		}
	}

	/* Populate descriptor */
	iobuf->head = iobuf->data = iobuf->tail = data;
	iobuf->end = ( data + len );

	return iobuf;
}
Пример #28
0
int main ()
{
#if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
  C c;
  if (((char *)static_cast <B3 *> (&c) - (char *)&c) % __alignof__ (C))
    return 1;
#endif
  return 0;
}
Пример #29
0
Файл: push-1.c Проект: pjump/gcc
foo (__m128 x, __m128 y ,__m128 z ,__m128 a, int size)
{
    aligned i;

    if (size != 5 || check_int (&i, __alignof__(i)) != i)
        abort ();

    r = a;
}
Пример #30
0
static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb)
{
	struct crypto_instance *inst;
	struct crypto_alg *alg;
	int err;

	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
	if (err)
		return ERR_PTR(err);

	alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
				  CRYPTO_ALG_TYPE_MASK);
	if (IS_ERR(alg))
		return ERR_CAST(alg);

	/* Block size must be >= 4 bytes. */
	err = -EINVAL;
	if (alg->cra_blocksize < 4)
		goto out_put_alg;

	/* If this is false we'd fail the alignment of crypto_inc. */
	if (alg->cra_blocksize % 4)
		goto out_put_alg;

	inst = crypto_alloc_instance("ctr", alg);
	if (IS_ERR(inst))
		goto out;

	inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER;
	inst->alg.cra_priority = alg->cra_priority;
	inst->alg.cra_blocksize = 1;
	inst->alg.cra_alignmask = alg->cra_alignmask | (__alignof__(u32) - 1);
	inst->alg.cra_type = &crypto_blkcipher_type;

	inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize;
	inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
	inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;

	inst->alg.cra_ctxsize = sizeof(struct crypto_ctr_ctx);

	inst->alg.cra_init = crypto_ctr_init_tfm;
	inst->alg.cra_exit = crypto_ctr_exit_tfm;

	inst->alg.cra_blkcipher.setkey = crypto_ctr_setkey;
	inst->alg.cra_blkcipher.encrypt = crypto_ctr_crypt;
	inst->alg.cra_blkcipher.decrypt = crypto_ctr_crypt;

	inst->alg.cra_blkcipher.geniv = "chainiv";

out:
	crypto_mod_put(alg);
	return inst;

out_put_alg:
	inst = ERR_PTR(err);
	goto out;
}