Exemple #1
0
int 
debug_init(void)
{
  int i;
  for (i=0; i < SAMPLE_SIZE; i++) {
    debug[i].caller = h2d(debugi[i].caller);
    debug[i].callee = h2d(debugi[i].callee);
    debug[i].caller_name_idx = debugi[i].caller_idx;
    debug[i].callee_name_idx = debugi[i].callee_idx;
  }
  return SAMPLE_SIZE;
}
void
CVMmemFree(CVMMemHandle *h)
{
    CVMMemPrivateData *d = h2d(h);

    /* FIXME: We should also destroy the private data and remove it
     *        from the link lists.
     */
    switch (d->allocType) {
    case CVM_MEM_ALLOC_MALLOC:
	free(d->dataStart.data);
	break;
    case CVM_MEM_ALLOC_MMAP:
#if 0
	CVMunmapAnonMemory(d->dataStart.data);
#endif
	break;
    case CVM_MEM_ALLOC_MEMALIGN:
	CVMmemalignFree(d->dataStart.data);
	break;
    default:
	CVMpanic("CVMmemFree: unknown alloc type\n");
    }
    free(d);
}
void
CVMmemSetMonitorMode(CVMMemHandle *h, CVMMemMonMode mode)
{
    CVMMemPrivateData *d = h2d(h);
    d->mode = mode; /* set the new mode */
    if (mode == CVM_MEM_MON_NONE) {
        /* disable write notify */      
        CVMmemDisableWriteNotify(h);
    } else if (mode == CVM_MEM_MON_FIRST_WRITE ||
               mode == CVM_MEM_MON_ALL_WRITES) {
        if (d->map == NULL) {
            CVMMemDirtyPages *map;
            map = (CVMMemDirtyPages*)malloc(
                          sizeof(CVMMemDirtyPages));
            if (map != NULL) {
                map->memMap = (CVMUint8*)calloc(
                    sizeof(CVMUint8), 
                    (ALIGNEDNEXT(d->end) - ALIGNED(d->dataStart.start)) /
                                    CVMgetPagesize());
	        if (map->memMap == NULL) {
                    free(map);
                    return;
                }
                map->numberOfDirtypages = 0;
                d->map = map;
   	    } else {
                return;
            }
        }
        CVMmemEnableWriteNotify(
            h, (CVMUint32*)d->dataStart.start, (CVMUint32*)d->end);
    }
    return;
}
void
CVMmemEnableWriteNotify(CVMMemHandle *h, CVMUint32* start, CVMUint32* end)
{
    CVMMemPrivateData *r = h2d(h);
    CVMAddr alignedStart = ALIGNED(start);
    CVMAddr alignedEnd = ALIGNEDNEXT(end);

    if (wnlLock == NULL) {
        wnlLock = malloc(sizeof(CVMMutex));
        CVMmutexInit(wnlLock);
    }
    CVMmutexLock(wnlLock);

    /* Add to the write notify list. */
    if (writeNotifyList == NULL) {
        r->nextWriteNotify = NULL;
    } else {
        r->nextWriteNotify = writeNotifyList;
    }
    writeNotifyList = r;

    CVMmutexUnlock(wnlLock);

    /* Protect the aligned region that contains the start and end to
     * enable write notify.
     */
    CVMmprotect((void*)alignedStart, (void*)alignedEnd, CVM_TRUE);
}
  void GeneralizedCylinder :: CalcHesse (const Point<3> & point, Mat<3> & hesse) const
  {
    Point<2> p2d, projp;
    double t, dist, val;
    Point<2> curvp;
    Vec<2> curvpp;
    Mat<2> h2d;
    Mat<3,2> vmat;
    int i, j, k, l;

    p2d = Point<2> (planee1 * (point - planep), planee2 * (point - planep));
    t = crosssection.ProjectParam (p2d);

    curvp = crosssection.CurvCircle (t);
    curvpp = p2d-curvp;
    dist = curvpp.Length();
    curvpp /= dist;

    h2d(0, 0) = (1 - curvpp(0) * curvpp(0) ) / dist;
    h2d(0, 1) = h2d(1, 0) = (- curvpp(0) * curvpp(1) ) / dist;
    h2d(1, 1) = (1 - curvpp(1) * curvpp(1) ) / dist;

    vmat(0,0) = planee1(0);
    vmat(1,0) = planee1(1);
    vmat(2,0) = planee1(2);
    vmat(0,1) = planee2(0);
    vmat(1,1) = planee2(1);
    vmat(2,1) = planee2(2);

    for (i = 0; i < 3; i++)
      for (j = 0; j < 3; j++)
        {
          val = 0;
          for (k = 0; k < 2; k++)
            for (l = 0; l < 2; l++)
              val += vmat(i,k) * h2d(k,l) * vmat(j,l);
          hesse(i,j) = val;
        }
  }
const CVMMemHandle *
CVMmemAddress2Handle(void *addr)
{
    CVMMemHandle *h;
    CVMAddr a = (CVMAddr)addr;
    if ((a & (pagesize-1)) == 0) {
	/* lookup handle */
	h = CVMmemFind(addr);
	CVMassert(h != NULL && h2d(h)->dataStart.data == addr);
    } else {
	h = ((CVMMemHandle **)a)[-1];
    }
    return h;
}
Exemple #7
0
static noinline char* put_dec(char *buf, unsigned long long num)
{
	int len = h2d(buf, 0, num);
	return buf + len;
}
Exemple #8
0
int
tokenuserinit(int flags, char *username, unsigned char *usecret, unsigned mode)
{
	TOKENDB_Rec tokenrec;
	TOKEN_CBlock secret;
	TOKEN_CBlock nulls;
	TOKEN_CBlock checksum;
	TOKEN_CBlock checktxt;
	DES_key_schedule key_schedule;

	memset(&secret, 0, sizeof(secret));

	/*
	 * If no user secret passed in, create one
	 */

	if ( (flags & TOKEN_GENSECRET) )
		tokenseed(&secret);
	else
		memcpy(&secret, usecret, sizeof(DES_cblock));

	DES_fixup_key_parity(&secret.cb);

	/*
	 * Check if the db record already exists.  If there's no
	 * force-init flag and it exists, go away. Else,
	 * create the user's db record and put to the db.
	 */


	if (!(flags & TOKEN_FORCEINIT) &&
	    tokendb_getrec(username, &tokenrec) == 0)
		return (1);

	memset(&tokenrec, 0, sizeof(tokenrec));
	strlcpy(tokenrec.uname, username, sizeof(tokenrec.uname));
	cb2h(secret, tokenrec.secret);
	tokenrec.mode = 0;
	tokenrec.flags = TOKEN_ENABLED | TOKEN_USEMODES;
	tokenrec.mode = mode;
	memset(tokenrec.reserved_char1, 0, sizeof(tokenrec.reserved_char1));
	memset(tokenrec.reserved_char2, 0, sizeof(tokenrec.reserved_char2));

	if (tokendb_putrec(username, &tokenrec))
		return (-1);

	/*
	 * Check if the shared secret was generated here. If so, we
	 * need to inform the user about it in order that it can be
	 * programmed into the token. See tokenverify() (above) for
	 * discussion of cipher generation.
	 */

	if (!(flags & TOKEN_GENSECRET)) {
		memset(&secret, 0, sizeof(secret));
		return (0);
	}

	printf("Shared secret for %s\'s token: "
	    "%03o %03o %03o %03o %03o %03o %03o %03o\n",
	    username, secret.cb[0], secret.cb[1], secret.cb[2], secret.cb[3],
	    secret.cb[4], secret.cb[5], secret.cb[6], secret.cb[7]);

	DES_key_sched(&secret.cb, &key_schedule);
	memset(&secret, 0, sizeof(secret));
	memset(&nulls, 0, sizeof(nulls));
	DES_ecb_encrypt(&nulls.cb, &checksum.cb, &key_schedule, DES_ENCRYPT);
	memset(&key_schedule, 0, sizeof(key_schedule));
	HTONL(checksum.ul[0]);
	snprintf(checktxt.ct, sizeof(checktxt.ct), "%8.8x", checksum.ul[0]);
	printf("Hex Checksum: \"%s\"", checktxt.ct);

	h2d(checktxt.ct);
	printf("\tDecimal Checksum: \"%s\"\n", checktxt.ct);

	return (0);
}
Exemple #9
0
int
tokenverify(char *username, char *challenge, char *response)
{
	char	*state;
	TOKENDB_Rec tokenrec;
	TOKEN_CBlock tmp;
	TOKEN_CBlock cmp_text;
	TOKEN_CBlock user_seed;
	TOKEN_CBlock cipher_text;
	DES_key_schedule key_schedule;


	memset(cmp_text.ct, 0, sizeof(cmp_text.ct));
	memset(user_seed.ct, 0, sizeof(user_seed.ct));
	memset(cipher_text.ct, 0, sizeof(cipher_text.ct));
	memset(tokennumber.ct, 0, sizeof(tokennumber.ct));

	(void)strtok(challenge, "\"");
	state = strtok(NULL, "\"");
	tmp.ul[0] = strtoul(state, NULL, 10);
	snprintf(tokennumber.ct, sizeof(tokennumber.ct), "%8.8u",tmp.ul[0]);

	/*
	 * Retrieve the db record for the user. Nuke it as soon as
	 * we have translated out the user's shared secret just in
	 * case we (somehow) get core dumped...
	 */

	if (tokendb_getrec(username, &tokenrec))
		return (-1);

	h2cb(tokenrec.secret, &user_seed);
	memset(&tokenrec.secret, 0, sizeof(tokenrec.secret));

	if (!(tokenrec.flags & TOKEN_ENABLED))
		return (-1);

	/*
	 * Compute the anticipated response in hex. Nuke the user's
	 * shared secret asap.
	 */

	DES_fixup_key_parity(&user_seed.cb);
	DES_key_sched(&user_seed.cb, &key_schedule);
	memset(user_seed.ct, 0, sizeof(user_seed.ct));
	DES_ecb_encrypt(&tokennumber.cb, &cipher_text.cb, &key_schedule,
	    DES_ENCRYPT);
	memset(&key_schedule, 0, sizeof(key_schedule));

	/*
	 * The token thinks it's descended from VAXen.  Deal with i386
	 * endian-ness of binary cipher prior to generating ascii from first
	 * 32 bits.
	 */

	HTONL(cipher_text.ul[0]);
	snprintf(cmp_text.ct, sizeof(cmp_text.ct), "%8.8x", cipher_text.ul[0]);

	if (tokenrec.mode & TOKEN_PHONEMODE) {
		/*
		 * If we are a CRYPTOCard, we need to see if we are in
		 * "telephone number mode".  If so, transmogrify the fourth
		 * digit of the cipher.  Lower case response just in case
		 * it's * hex.  Compare hex cipher with anticipated response
		 * from token.
		 */

		lcase(response);

		if (response[3] == '-')
			cmp_text.ct[3] = '-';
	}

	if ((tokenrec.mode & TOKEN_HEXMODE) && !strcmp(response, cmp_text.ct))
		return (0);

	/*
	 * No match against the computed hex cipher.  The token could be
	 * in decimal mode.  Pervert the string to magic decimal equivalent.
	 */

	h2d(cmp_text.ct);

	if ((tokenrec.mode & TOKEN_DECMODE) && !strcmp(response, cmp_text.ct))
		return (0);

	return (-1);
}
 //generates a random uint long long (for testing)
 xmr_amount randXmrAmount(xmr_amount upperlimit) {
     return h2d(skGen()) % (upperlimit);
 }
CVMMemType
CVMmemGetType(const CVMMemHandle *h)
{
    return h2d(h)->type;
}
CVMMemMonMode
CVMmemGetMonitorMode(CVMMemHandle *h)
{
    return h2d(h)->mode;
}