예제 #1
0
static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
{
    if (ioctl(fd, CIOCFSESSION, &CDATA(ctx)->ses) == -1)
        err("CIOCFSESSION failed");

    OPENSSL_free(CDATA(ctx)->key);

    return 1;
}
예제 #2
0
파일: game.c 프로젝트: Ilych/life-simple
void evolv()
{

	int i,j,pop;
	
	// copy data to buffer
	memcpy (cells_buf, cells, SIZEWI);


	for (i=1; i<=wlines; i++)
		for (j=1; j<=wcols; j++)
		{
			pop=0;

			// NW 
			if (CBDATA((i-1),(j-1))==1)
				pop++;
			// N
			if (CBDATA((i-1),j)==1)
				pop++;
			// NE
			if (CBDATA((i-1),j+1)==1)
				pop++;
			// E
			if (CBDATA(i,j+1)==1)
				pop++;
			// SE
			if (CBDATA((i+1),j+1)==1)
				pop++;
			// S
			if (CBDATA((i+1),j)==1)
				pop++;
			// SW
			if (CBDATA((i+1),j-1)==1)
				pop++;
			// W
			if (CBDATA(i,j-1)==1)
				pop++;


			switch (pop)
			{
			case 0: case 1: case 4: case 5:
			case 6: case 7: case 8:
				CDATA(i,j)=0;
				break;
			case 3:
				CDATA(i,j)=1;
				break;
			}
		}

	


}
예제 #3
0
static void
_dxf_captureZoomBox(tdmInteractor I, void *udata, float rot[4][4])
{
  register long *bp, *image ;
  register int i, iw, ih, n, y2 ;
  int x1, x2, y1 ;
  static long buff[4096] ;
  DEFDATA(I, tdmZoomData) ;

  readsource(SRC_FRONT);

  iw = CDATA(iw) ;
  ih = CDATA(ih) ;
  image = (long *)CDATA(image) ;

  /* clip coords to image to avoid invalid raster positions */
  x1 = (PDATA(x1)<0 ? 0 : (PDATA(x1)>(iw-1) ? iw-1 : PDATA(x1))) ;
  x2 = (PDATA(x2)<0 ? 0 : (PDATA(x2)>(iw-1) ? iw-1 : PDATA(x2))) ;
  y1 = (PDATA(y1)<0 ? 0 : (PDATA(y1)>(ih-1) ? ih-1 : PDATA(y1))) ;
  y2 = (PDATA(y2)<0 ? 0 : (PDATA(y2)>(ih-1) ? ih-1 : PDATA(y2))) ;

  lrectread (x1, y1, x2, y1, (const unsigned long *)image+(x1 + y1*iw)) ;
  if (y1 < (ih+1))
      lrectread (x1, y1+1, x2, y1+1,
			(const unsigned long *)image+(x1 + (y1+1)*iw)) ;

  lrectread (x1, y2, x2, y2, (const unsigned long *)image+(x1 + y2*iw)) ;
  if (y2 < (ih+1))
      lrectread (x1, y2+1, x2, y2+1, 
			(const unsigned long *)image+(x1 + (y2+1)*iw)) ;

  lrectread (x1, y1, x1, y2, (const unsigned long *)buff) ;
  for (bp=buff, n=x1+(y1*iw), i=y1 ; i<=y2 ; i++, n+=iw)
      image[n] = *bp++;
  if (x1 < iw-1)
  {
      lrectread (x1+1, y1, x1+1, y2, (const unsigned long *)buff) ;
      for (bp=buff, n=(x1+1)+(y1*iw), i=y1 ; i<=y2 ; i++, n+=iw)
	  image[n] = *bp++;
  }

  lrectread (x2, y1, x2, y2, (const unsigned long *)buff) ;
  for (bp=buff, n=x2+(y1*iw), i=y1 ; i<=y2 ; i++, n+=iw)
      image[n] = *bp++;

  if (x2 < iw-1)
  {
      lrectread (x2+1, y1, x2+1, y2, (const unsigned long *)buff) ;
      for (bp=buff, n=(x2+1)+(y1*iw), i=y1 ; i<=y2 ; i++, n+=iw)
	  image[n] = *bp++;
  }
}
예제 #4
0
static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
			       const unsigned char *key,int klen)
    {
    if(!dev_crypto_init(CDATA(ctx)))
	return 0;

    CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
    if (CDATA(ctx)->key == NULL)
        return 0;

    assert(ctx->cipher->iv_len <= MAX_HW_IV);

    memcpy(CDATA(ctx)->key,key,klen);
    
    CDATA(ctx)->cipher=cipher;
    CDATA(ctx)->keylen=klen;

    if (ioctl(fd,CIOCGSESSION,CDATA(ctx)) == -1)
	{
	err("CIOCGSESSION failed");
	return 0;
	}
    return 1;
    }
static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
			       const unsigned char *key,int klen)
    {
    if(!dev_crypto_init(CDATA(ctx)))
	return 0;

    CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);

    TINYCLR_SSL_ASSERT(ctx->cipher->iv_len <= MAX_HW_IV);

    TINYCLR_SSL_MEMCPY(CDATA(ctx)->key,key,klen);
    
    CDATA(ctx)->cipher=cipher;
    CDATA(ctx)->keylen=klen;

    if (TINYCLR_SSL_IOCTL(fd,CIOCGSESSION,CDATA(ctx)) == -1)
	{
	err("CIOCGSESSION failed");
	return 0;
	}
    return 1;
    }
예제 #6
0
static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
                             const unsigned char *in, unsigned int inl)
{
    struct crypt_op cryp;
    unsigned char lb[MAX_HW_IV];

    if (!inl)
        return 1;

    assert(CDATA(ctx));
    assert(!dev_failed);

    memset(&cryp, '\0', sizeof cryp);
    cryp.ses = CDATA(ctx)->ses;
    cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
    cryp.flags = 0;
    cryp.len = inl;
    assert((inl & (ctx->cipher->block_size - 1)) == 0);
    cryp.src = (caddr_t) in;
    cryp.dst = (caddr_t) out;
    cryp.mac = 0;
    if (ctx->cipher->iv_len)
        cryp.iv = (caddr_t) ctx->iv;

    if (!ctx->encrypt)
        memcpy(lb, &in[cryp.len - ctx->cipher->iv_len], ctx->cipher->iv_len);

    if (ioctl(fd, CIOCCRYPT, &cryp) == -1) {
        if (errno == EINVAL) {  /* buffers are misaligned */
            unsigned int cinl = 0;
            char *cin = NULL;
            char *cout = NULL;

            /* NB: this can only make cinl != inl with stream ciphers */
            cinl = (inl + 3) / 4 * 4;

            if (((unsigned long)in & 3) || cinl != inl) {
                cin = OPENSSL_malloc(cinl);
                memcpy(cin, in, inl);
                cryp.src = cin;
            }

            if (((unsigned long)out & 3) || cinl != inl) {
                cout = OPENSSL_malloc(cinl);
                cryp.dst = cout;
            }

            cryp.len = cinl;

            if (ioctl(fd, CIOCCRYPT, &cryp) == -1) {
                err("CIOCCRYPT(2) failed");
                printf("src=%p dst=%p\n", cryp.src, cryp.dst);
                abort();
                return 0;
            }

            if (cout) {
                memcpy(out, cout, inl);
                OPENSSL_free(cout);
            }
            if (cin)
                OPENSSL_free(cin);
        } else {
            err("CIOCCRYPT failed");
            abort();
            return 0;
        }
    }

    if (ctx->encrypt)
        memcpy(ctx->iv, &out[cryp.len - ctx->cipher->iv_len],
               ctx->cipher->iv_len);
    else
        memcpy(ctx->iv, lb, ctx->cipher->iv_len);

    return 1;
}