示例#1
0
文件: mat_SDCZ_c.c 项目: akabe/lacaml
CAMLprim value LFUN(mat_axpy_stub)(
  value vALPHA,
  value vM, value vN,
  value vXR, value vXC, value vX,
  value vYR, value vYC, value vY)
{
  CAMLparam2(vX, vY);
  integer GET_INT(M), GET_INT(N);
  if (M > 0 && N > 0) {
    CREATE_NUMBER(ALPHA);
    MAT_PARAMS(X);
    MAT_PARAMS(Y);
    INIT_NUMBER(ALPHA);
    caml_enter_blocking_section();
      if (rows_X == M && rows_Y == M) {
        integer MN = M * N;
        FUN(axpy)(&MN, &ALPHA, X_data, &integer_one, Y_data, &integer_one);
      } else {
        NUMBER *X_last = X_data + rows_X * N;
        do {
          FUN(axpy)(&M, &ALPHA, X_data, &integer_one, Y_data, &integer_one);
          X_data += rows_X;
          Y_data += rows_Y;
        } while (X_data != X_last);
      }
    caml_leave_blocking_section();
  }

  CAMLreturn(Val_unit);
}
示例#2
0
文件: mat_SDCZ_c.c 项目: akabe/lacaml
CAMLprim value LFUN(scal_mat_stub)(
  value vM, value vN,
  value vALPHA,
  value vAR, value vAC, value vA)
{
  CAMLparam1(vA);
  integer GET_INT(M), GET_INT(N);

  if ( M > 0 && N > 0) {
    CREATE_NUMBER(ALPHA);
    MAT_PARAMS(A);
    INIT_NUMBER(ALPHA);
    caml_enter_blocking_section();
      if (rows_A == M) {
        integer MN = M * N;
        FUN(scal)(&MN, &ALPHA, A_data, &integer_one);
      } else {
        NUMBER *A_last = A_data + rows_A * N;
        do {
          FUN(scal)(&M, &ALPHA, A_data, &integer_one);
          A_data += rows_A;
        } while (A_data != A_last);
      }
    caml_leave_blocking_section();
  }

  CAMLreturn(Val_unit);
}
示例#3
0
nemo_main()
{
  int n=getiparam("n");
  int iter=getiparam("iter");
  int m=getiparam("m");
  int seed = init_xrandom(getparam("seed"));
  int i,j,k,l;
  real *x, sum;
  real t0,t1,t2;

  init_timers(100);
  stamp_timers(0);

  x = (real *) allocate(n*sizeof(real));

  for (i=0; i<n; i++)         /* init the whole array */
    x[i] = xrandom(0.0,1.0);
  for (i=0; i<m; i++)         /* cache it in again ? */
    x[i] = xrandom(0.0,1.0);

  sum = 0.0;
  t0 = cputime();
  stamp_timers(1);
  if (m==0) {                         /* do it in one sweep, the N^2 algorithm */
    stamp_timers(2);
    for (l=0; l<iter;  l++)
      for (j=0; j<n; j++)
	for (i=0; i<n; i++)
	  sum += FUN(x[i],x[j]);
    stamp_timers(3);
  } else {                            /* N/M times a small M*M patch that may be in cache */
    stamp_timers(2);
    for (l=0; l<iter; l++)
      for (k=0; k<n-m; k++)
	for (j=k; j<k+m; j++)
	  for (i=k; i<k+m; i++)
	    sum += FUN(x[i],x[j]);
    stamp_timers(3);
  }
  stamp_timers(4);
  t1 = cputime();
  if (m)
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*m*m*n/(t1-t0)/60.0/1e6);
  else
    printf("%d %d %d sum=%lg Mops=%lg\n",
	 n,iter,m,sum,iter*n*n/(t1-t0)/60.0/1e6);
  stamp_timers(5);
  printf("%Ld %Ld %Ld %Ld %Ld\n",
	 diff_timers(0,1),
	 diff_timers(1,2),
	 diff_timers(2,3),
	 diff_timers(3,4),
	 diff_timers(4,5));
}
示例#4
0
int _osd_sem_init(osd_sem_t *sem, int pshared, int value SEM_FILELINEARGS)
{
	sem_t *s = &sem->posix;
	int rc;
	FUN("osd_sem_init");

	if (NULL == sem) {
		LOG(L_ERROR,("sem is NULL%s\n",
			at_file_line(SEM_FILELINEVARS)));
		errno = EINVAL;
		return -1;
	}
	/* shutting down? */
	if (SHUTDOWN()) {
		return 0;
	}
	if (MY_SEM_MAGIC == sem->magic) {
		LOG(L_ERROR,("sem %p already initialized%s\n",
			sem, at_file_line(SEM_FILELINEVARS)));
		sem->pid = 0;
		/* Destroy and initialize semaphore again */
		sem_destroy(s);
		sem_init(s, 0, value);
		return 0;
	}
	sem->pid = 0;
	rc = sem_init(s, pshared, value);
	if (0 == rc)
		sem->magic = MY_SEM_MAGIC;
	return rc;
}
示例#5
0
static void ipv4_clear_list(ipv4_rangelist_item_t **list,
                            size_t *list_items,
                            size_t *list_alloc)
{
#ifndef IPLIST_IGNORE_DESCRIPTION_FIELD
	size_t i;
#endif

	FUN("ipv4_clear_list");

#ifndef IPLIST_IGNORE_DESCRIPTION_FIELD
	for (i = 0; i < *list_items; i++) {
		if ((*list)[i].description != NULL) {
			xfree((*list)[i].description);
			(*list)[i].description = NULL;
		}
	}
#endif /* ! IPLIST_IGNORE_DESCRIPTION_FIELD */
	if (*list_alloc != 0) {
		xfree(*list);
	}
	*list_alloc = 0;
	*list_items = 0;
	*list = NULL;
}
示例#6
0
CAMLprim value LFUN(sqr_nrm2_stub)(
  value vSTABLE, value vN, value vOFSX, value vINCX, value vX)
{
  CAMLparam1(vX);

  integer GET_INT(N), GET_INT(INCX);
  REAL res;

  VEC_PARAMS(X);

  caml_enter_blocking_section();  /* Allow other threads */
  if (Bool_val(vSTABLE)) {
#ifndef LACAML_DOUBLE
  res = scnrm2_(&N, X_data, &INCX);
#else
  res = dznrm2_(&N, X_data, &INCX);
#endif
  res *= res;
  } else {
    COMPLEX cres = FUN(dotc)(&N, X_data, &INCX, X_data, &INCX);
    res = cres.r;
  }
  caml_leave_blocking_section();  /* Disallow other threads */

  CAMLreturn(caml_copy_double(res));
}
示例#7
0
void ipv4_clear_lists()
{
	FUN("ipv4_clear_lists");

	ipv4_clear_list(&white_list, &white_list_items, &white_list_alloc);
	ipv4_clear_list(&black_list, &black_list_items, &black_list_alloc);
}
示例#8
0
/***********************************************************************
 *  init()
 ***********************************************************************/
int crypt0_init(void **pptr, int init, void *data, size_t size)
{
	crypt0_t *c;
	FUN("crypt0_init");

	if (NULL == pptr) {
		LOGS(L_CRYPTO,L_ERROR,("pptr is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (0 != init) {
		LOGS(L_CRYPTO,L_ERROR,("init is not 0\n"));
		errno = EINVAL;
		return -1;
	}
	c = (crypt0_t *)xcalloc(sizeof(crypt0_t), 1);
	*pptr = c;

	c->magic = CRYPT0_MAGIC;

	(void)data;
	(void)size;

	return 0;
}
int main(int argc, char **argv)
{
  int k = argc == 2 ? strtol(argv[1], 0, 0) : 10;
  printf("%d\n", A(FUN(MAKE_ARG(f1), MAKE_ARG(f_1), MAKE_ARG(f_1),
                       MAKE_ARG(f1), MAKE_ARG(f0))));
  return 0;
}
示例#10
0
/***********************************************************************
 *  crypto()
 ***********************************************************************/
int crypt0_crypto(void)
{
	FUN("crypt0_crypto");

	/* no initialization required */

	return 0;
}
示例#11
0
int main(){

int val1 = 10;
int val12 = 20;

printf("%d\n",FUN(val1,2));

return 0;
}
示例#12
0
static bool module_allow(const char *path, char **function) {
    void     *base        = NULL;
    size_t    size        = 0;
    Elf_Ehdr *ehdr        = NULL;
    Elf_Shdr *shdr        = NULL;
    Elf_Sym  *dsymtab     = NULL;
    Elf_Sym  *dsymtab_end = NULL;
    char     *dstrtab     = NULL;
    FILE     *file        = fopen(path, "r");

    if (!file)
        return false;

    fseek(file, 0, SEEK_END);
    size = ftell(file);
    base = malloc(size);
    fseek(file, 0, SEEK_SET);
    fread(base, size, 1, file);
    fclose(file);

    ehdr = base;
    shdr = (Elf_Shdr*)(base + ehdr->e_shoff);
    for (size_t i = 0; i < ehdr->e_shnum; i++) {
        if (shdr[i].sh_type == SHT_DYNSYM) {
            dsymtab     = (Elf_Sym*)(base + shdr[i].sh_offset);
            dsymtab_end = (Elf_Sym*)((char *)dsymtab + shdr[i].sh_size);
            dstrtab     = (char *)(base + shdr[shdr[i].sh_link].sh_offset);
        }
    }

    while (dsymtab < dsymtab_end) {
        if (FUN(dsymtab->st_info) == STT_FUNC || FUN(dsymtab->st_info) == STT_NOTYPE) {
            if (!module_allow_symbol(&dstrtab[dsymtab->st_name])) {
                *function = strdup(&dstrtab[dsymtab->st_name]);
                free(base);
                return false;
            }
        }
        dsymtab++;
    }

    free(base);
    return true;
}
示例#13
0
/**
 * @brief Crypt a (memory mapped) buffer using the given key.
 *
 * This is the workhorse for key contents encryption an decryption.
 * The dragon cipher context is allocated from the stack, and
 * destroyed at the end of the function.
 *
 * @param key pointer to the EK5 hash used as seed
 * @param buff pointer to the (memory mapped) byte array
 * @param size size of the byte array in bytes
 * @param flags flags specifying if a header should be skipped
 *
 * @result zero on success
 */
int key_crypt(uint8_t *key, void *buff, size_t size, int flags)
{
	uint8_t *pb = (uint8_t *)buff;
	dragon_t dctx;
	uint32_t a, b, c, d, e, f, t;
	uint32_t u32[4];
	size_t i, j;
	FUN("key_crypt");

	u32[0] = ntohl(*(uint32_t*)&key[ 0]);
	u32[1] = ntohl(*(uint32_t*)&key[ 4]);
	u32[2] = ntohl(*(uint32_t*)&key[ 8]);
	u32[3] = ntohl(*(uint32_t*)&key[12]);

	DINIT128(dctx, u32, iv1, a, b, c, d, e, f, t, j);

	if (0 == (flags & KEY_CRYPT_GZ)) {
		/* Crypt a complete buffer (e.g. a file fragment) */
		for (i = 0; i < size; i++) {
			switch (i % 8) {
			case 0:
				DGEN(dctx, a, b, c, d, e, f, t);
				if (i + 8 <= size) {
					*(uint32_t*)pb ^= htonl(a);
					pb += 4;
					*(uint32_t*)pb ^= htonl(e);
					pb += 4;
					i += 7;
					continue;
				}
				*pb++ ^= (uint8_t)(a >> 24);
				break;
			case 1:
				*pb++ ^= (uint8_t)(a >> 16);
				break;
			case 2:
				*pb++ ^= (uint8_t)(a >> 8);
				break;
			case 3:
				*pb++ ^= (uint8_t)a;
				break;
			case 4:
				*pb++ ^= (uint8_t)(e >> 24);
				break;
			case 5:
				*pb++ ^= (uint8_t)(e >> 16);
				break;
			case 6:
				*pb++ ^= (uint8_t)(e >> 8);
				break;
			case 7:
				*pb++ ^= (uint8_t)e;
				break;
			}
		}
	} else {
示例#14
0
CAMLprim value LFUN(sqr_nrm2_stub)(
  value vSTABLE, value vN, value vOFSX, value vINCX, value vX)
{
  CAMLparam1(vX);

  integer GET_INT(N), GET_INT(INCX);
  doublereal res;

  VEC_PARAMS(X);

  caml_enter_blocking_section();  /* Allow other threads */
  if (Bool_val(vSTABLE)) {
    res = FUN(nrm2)(&N, X_data, &INCX);
    res *= res;
  } else res = FUN(dot)(&N, X_data, &INCX, X_data, &INCX);
  caml_leave_blocking_section();  /* Disallow other threads */

  CAMLreturn(caml_copy_double(res));
}
示例#15
0
int ipv4_white_list_match(uint32_t addr, char **descr_ret)
{
	int rv;

	FUN("ipv4_white_list_match");

	rv = list_match(addr, 
		&white_list, &white_list_items, &white_list_alloc, descr_ret);

	return rv;
}
示例#16
0
int ipv4_black_list_read(const char *file_name)
{
	int rv;

	FUN("ipv4_black_list_read");

	rv = list_read(file_name,
                    &black_list, &black_list_items, &black_list_alloc);

     return rv;
}
示例#17
0
static void plist(shm_node_t *head)
{
	shm_node_t *c;
	FUN("plist");

	LOGS(L_SHM,L_ERROR,("=== list starts at 0x%x ===\n",
		(uint32_t)head));
	c = head;
	while (NULL != c) {
		pnode(c);
		c = c->x.next;
	}
}
示例#18
0
static int list_match(uint32_t addr,
                      ipv4_rangelist_item_t **list,
                      size_t *list_items,
                      size_t *list_alloc,
                      char **descr_ret)
{
	size_t i;
	uint32_t haddr;
	int rv = 0;

	FUN("list_match");

	/* avoid unused warning */
	(void)list_alloc;

	haddr = ntohl(addr);

	/*
	 * We could do some kind of modified binary search here, but this
	 * seems to take less than a millisecond in pentium with this
	 * primitive linear search with blacklist of more than 100000
	 * ranges, so I won't bother for now.
	 */
	for (i = 0; i < *list_items; i++) {
		if ((haddr >= ((*list)[i]).range_start) &&
			(haddr <= ((*list)[i]).range_end)) {
			rv = 1;
			goto out;
		}
		if (haddr < ((*list)[i]).range_start) {
			/*
			 * Since the list is ordered, all following ranges
			 * start above the address we are looking for.
			 */
			goto out;
		}
	}

out:
	if (descr_ret != NULL) {
#ifndef IPLIST_IGNORE_DESCRIPTION_FIELD
		if (rv != 0) {
			*descr_ret = ((*list)[i]).description;
		}
#else /* ! IPLIST_IGNORE_DESCRIPTION_FIELD */
		*descr_ret = NULL;
#endif /* ! IPLIST_IGNORE_DESCRIPTION_FIELD */
	}
	return rv;
}
示例#19
0
bool
plugin_init(plugin_h self)
{
   plugin.self = self;

   plugin_h orbment, configuration;
   if (!(orbment = import_plugin(self, "orbment")) ||
       !(configuration = import_plugin(self, "configuration")))
      return false;

   if (!(add_hook = import_method(self, orbment, "add_hook", "b(h,c[],fun)|1")) ||
       !(configuration_get = import_method(self, configuration, "get", "b(c[],c,v)|1")))
      return false;

   return add_hook(self, "compositor.ready", FUN(do_autostart, "v(v)|1"));
}
示例#20
0
/***********************************************************************
 *  decrypt_msg()
 ***********************************************************************/
int crypt0_decrypt_msg(void *ptr, void *plaintext, void *ciphertext,
	size_t *outsize, size_t insize)
{
	crypt0_t *c = (crypt0_t *)ptr;
	FUN("crypt0_decrypt_msg");

	if (NULL == ptr) {
		LOGS(L_CRYPTO,L_ERROR,("ptr is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (NULL == ciphertext) {
		LOGS(L_CRYPTO,L_ERROR,("ciphertext is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (NULL == plaintext) {
		LOGS(L_CRYPTO,L_ERROR,("plaintext is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (NULL == outsize) {
		LOGS(L_CRYPTO,L_ERROR,("outsize is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (insize > *outsize) {
		LOGS(L_CRYPTO,L_ERROR,("outsize is too small (have %x, want %x)\n",
			(unsigned)*outsize, (unsigned)insize));
		errno = ENOMEM;
		return -1;
	}
	if (CRYPT0_MAGIC != c->magic) {
		LOGS(L_CRYPTO,L_ERROR,("magic is not 0x%x\n",
			CRYPT0_MAGIC));
		errno = EINVAL;
		return -1;
	}
	if (ciphertext != plaintext) {
		memcpy(plaintext, ciphertext, insize);
	}
	c->decrypt_count += insize;

	*outsize = insize;
	return 0;
}
示例#21
0
static void pnode(shm_node_t *n)
{
	FUN("pnode");
#if	SHM_DEBUG
	LOGS(L_SHM,L_ERROR,
		("%#x: rsize=%#x usize=%#x addr=%#x pid=%u file=%s:%u next=0x%x\n",
		(unsigned)n, (unsigned)n->x.rsize, (unsigned)n->x.usize,
		(unsigned)ADDR(n), (unsigned)n->x.pid, (unsigned)n->x.next,
		(char *)((NULL != n->x.file) ? n->x.file : "unknown"),
		(unsigned)n->x.line));
#else
	LOGS(L_SHM,L_ERROR,
		("%#x: rsize=%#x usize=%#x addr=%#x pid=%u next=0x%x\n",
		(unsigned)n, (unsigned)n->x.rsize, (unsigned)n->x.usize,
		(unsigned)ADDR(n), (unsigned)n->x.pid, (unsigned)n->x.next));
#endif
}
示例#22
0
/**
 * @brief Check and decode a base64 encoded SSK (sub space key).
 *
 * Convert a base64 encoded SSK into the internal representation.
 * The string uri may be prepended by a protocol specifier
 * URI_PROTO or the alternative URI_PROTO_ALT.
 * The function detects public SSKs by their extension, which
 * is either BMCA or, for the sake of Freenet compatibility, PagM.
 * The four characters are just the base64 representation of the
 * key type and log2size.
 *
 * @param key pointer to a key to be set
 * @param uri pointer to a string containing the key in base64 representation.
 *
 * @result zero on success, non-zero on error (decoding base64)
 */
int str_ssk(chkey_t *key, const char *uri)
{
	uint8_t key1[SHA1SIZE+1+2];
	size_t size;
	int rc = 0;
	FUN("str_ssk");

	if (0 == strncmp(uri, URI_PROTO, strlen(URI_PROTO))) {
		uri += strlen(URI_PROTO);
	} else if (0 == strncmp(uri, URI_PROTO_ALT, strlen(URI_PROTO_ALT))) {
		uri += strlen(URI_PROTO_ALT);
	}
	if (0 == strncmp(uri, URI_CHK, strlen(URI_CHK))) {
		uri += strlen(URI_CHK);
	}
	if (0 == strncmp(uri, URI_SSK, strlen(URI_SSK))) {
		uri += strlen(URI_SSK);
	}

	memset(key1, 0, sizeof(key1));
	rc = base64_decode(key1, &size, uri);
	LOG(L_MINOR,("base64_decode() size %u; log2size:%x, keytype:%02x%02x\n",
		(unsigned)size, key1[SHA1SIZE+0], key1[SHA1SIZE+1], key1[SHA1SIZE+2]));
	memcpy(key->sha1.digest, key1, SHA1SIZE);
	key->log2size = key1[SHA1SIZE+0];
	key->type[0] = key1[SHA1SIZE+1];
	key->type[1] = key1[SHA1SIZE+2];
	/* detect PAgM SSK public keys */
	if (key->log2size == 0x3e &&
		key->type[0] == 0x00 &&
		key->type[1] == 0xc8) {
		LOG(L_MINOR,("fake Freenet public SSK@ detected\n"));
		key->log2size = log2size(2*SHA1SIZE);
		key->type[0] = MSB(K_SSK_P);
		key->type[1] = LSB(K_SSK_P);
	} else if (key->log2size != log2size(2*SHA1SIZE) ||
		key->type[0] != MSB(K_SSK_P) ||
		key->type[1] != LSB(K_SSK_P)) {
		key->log2size = log2size(SHA1SIZE);
		key->type[0] = MSB(K_SSK_S);
		key->type[1] = LSB(K_SSK_S);
	}
	memset(key->ek5.digest, 0, sizeof(key->ek5.digest));

	return rc;
}
示例#23
0
/**
 * @brief Check and decode a base64 encoded key.
 *
 * Convert a base64 encoded key into the internal representation.
 * The string uri may be prepended by a protocol specifier
 * URI_PROTO or the alternative URI_PROTO_ALT.
 *
 * @param key pointer to a key to be set
 * @param uri pointer to a string containing the key in base64 representation.
 *
 * @result zero on success, non-zero on error (decoding base64)
 */
int str_key(chkey_t *key, const char *uri)
{
	uint8_t key1[SHA1SIZE+1+2];
	uint8_t key2[EK5SIZE];
	size_t size;
	int rc = 0;
	FUN("str_key");

	memset(key1, 0, sizeof(key1));
	memset(key2, 0, sizeof(key2));

	if (0 == strncmp(uri, URI_PROTO, strlen(URI_PROTO))) {
		uri += strlen(URI_PROTO);
	} else if (0 == strncmp(uri, URI_PROTO_ALT, strlen(URI_PROTO_ALT))) {
		uri += strlen(URI_PROTO_ALT);
	}
	if (0 == strncmp(uri, URI_CHK, strlen(URI_CHK))) {
		uri += strlen(URI_CHK);
	}
	if (0 == strncmp(uri, URI_SSK, strlen(URI_SSK))) {
		uri += strlen(URI_SSK);
	}

	size = SHA1SIZE + 1 + 2;
	if (0 != (rc = base64_decode(key1, &size, uri))) {
		goto bailout;
	}

	size = EK5SIZE;
	if (uri[KEY1SIZE] == ',') {
		if (0 != (rc = base64_decode(key2, &size, uri+KEY1SIZE+1))) {
			goto bailout;
		}
	}

	memcpy(key->sha1.digest, key1, sizeof(key->sha1.digest));
	key->log2size = key1[SHA1SIZE];
	key->type[0] = key1[SHA1SIZE+1];
	key->type[1] = key1[SHA1SIZE+1+1];
	memcpy(key->ek5.digest, key2, sizeof(key->ek5.digest));

bailout:
	return rc;
}
示例#24
0
static int item_compare(const void *item1, const void *item2)
{
	ipv4_rangelist_item_t *i1 = (ipv4_rangelist_item_t *)item1;
	ipv4_rangelist_item_t *i2 = (ipv4_rangelist_item_t *)item2;

	FUN("item_compare");

	if (i1->range_start < i2->range_start) {
		return -1;
	} else if (i1->range_start > i2->range_start) {
		return 1;
	}
	if (i1->range_end < i2->range_end) {
		return -1;
	} else if (i1->range_end > i2->range_end) {
		return 1;
	}
	return 0;
}
示例#25
0
void osd_usleep(int64_t usecs)
{
	int secs = (int)(usecs / 1000000);
	FUN("osd_usleep");

	if (usecs <= 0)
		return;
	if (secs > 0) {
		LOG(L_DEBUG,("sleep(%d)\n", secs));
		osd_sleep(secs);
		usecs -= (int64_t)1000000 * secs;
	}
	if (usecs > 0) {
#ifdef	__CYGWIN__
		if (usecs <= 500)
			usecs = 501;
#endif
		LOG(L_DEBUG,("usleep(%lld)\n", usecs));
		usleep(usecs);
	}
}
示例#26
0
/**
 * @brief Create content hash key for a byte array
 *
 * Create a content hash key for the given buffer and size.
 *
 * @param key pointer to the receiving chkey_t
 * @param buff byte array of data to hash
 * @param size size of byte array to has
 *
 * @result zero on success
 */
int key_chk(chkey_t *key, const void *buff, size_t size)
{
	key_state_t ks;
	FUN("key_chk");

	sha1_init(&ks.ss);
	sha1_append(&ks.ss, buff, size);
	sha1_finish(&ks.ss, &key->sha1);

	key->log2size = log2size(size);

	key->type[0] = MSB(K_CHK);
	key->type[1] = LSB(K_CHK);

	ek5_init(&ks.es);
	ek5_append(&ks.es, buff, size);
	ek5_finish(&ks.es, &key->ek5);

	key->padding = 0;

	return 0;
}
示例#27
0
/**
 * @brief Create the public SSK for a private SSK
 *
 * Create a public key from a private key,
 * simply by hashing the hex string of the SHA1 digest.
 *
 * @param key pointer to a key to receive the public SSK
 * @param ssk pointer to a key containing a private SSK
 *
 * @result zero on success
 */
int key_ssk_pub_from_priv(chkey_t *key, const chkey_t *ssk)
{
	char hex[SHA1SIZE*2+1];
	sha1_state_t sha1;
	size_t size;
	FUN("key_ssk_pub_from_priv");

	size = pm_snprintf(hex, sizeof(hex), "%s",
		sha1_hexstr(&ssk->sha1));

	sha1_init(&sha1);
	sha1_append(&sha1, hex, size);
	sha1_finish(&sha1, &key->sha1);

	key->type[0] = MSB(K_SSK_P);
	key->type[1] = LSB(K_SSK_P);
	key->log2size = log2size(size);

	memset(&key->ek5, 0, sizeof(key->ek5));

	return 0;
}
示例#28
0
/***********************************************************************
 *  exit()
 ***********************************************************************/
int crypt0_exit(void *ptr)
{
	crypt0_t *c = ptr;
	FUN("crypt0_exit");

	if (NULL == ptr) {
		LOGS(L_CRYPTO,L_ERROR,("pptr is NULL\n"));
		errno = EINVAL;
		return -1;
	}
	if (CRYPT0_MAGIC != c->magic) {
		LOGS(L_CRYPTO,L_ERROR,("magic is %x (!= %x)\n",
			c->magic, CRYPT0_MAGIC));
		errno = EINVAL;
		return -1;
	}

	memset(c, 0, sizeof(*c));
	xfree(ptr);

	return 0;
}
示例#29
0
文件: mat_SDCZ_c.c 项目: akabe/lacaml
CAMLprim value LFUN(transpose_copy_stub)(
  value vM, value vN,
  value vAR, value vAC, value vA,
  value vBR, value vBC, value vB)
{
  CAMLparam2(vA, vB);
  integer GET_INT(M), GET_INT(N);

  if (M > 0 && N > 0) {
    MAT_PARAMS(A);
    MAT_PARAMS(B);
    NUMBER *A_last = A_data + rows_A * N;
    caml_enter_blocking_section();
      do {
        FUN(copy)(&M, A_data, &integer_one, B_data, &rows_B);
        A_data += rows_A;
        B_data++;
      } while (A_data != A_last);
    caml_leave_blocking_section();
  }

  CAMLreturn(Val_unit);
}
示例#30
0
文件: mat_SDCZ_c.c 项目: akabe/lacaml
CAMLprim value LFUN(scal_rows_stub)(
  value vM, value vN,
  value vOFSALPHAs, value vALPHAs,
  value vAR, value vAC, value vA)
{
  CAMLparam2(vALPHAs, vA);
  integer GET_INT(M), GET_INT(N);

  if (M > 0 && N > 0) {
    VEC_PARAMS(ALPHAs);
    MAT_PARAMS(A);
    NUMBER *A_last = A_data + M;
    caml_enter_blocking_section();
      do {
        FUN(scal)(&N, ALPHAs_data, A_data, &rows_A);
        A_data++;
        ALPHAs_data++;
      } while (A_data != A_last);
    caml_leave_blocking_section();
  }

  CAMLreturn(Val_unit);
}