示例#1
0
void CItem::Spawn_KillChildren()
{
	// kill all creatures spawned from this !
	DEBUG_CHECK( IsType(IT_SPAWN_CHAR));
	int iCurrent = m_itSpawnChar.m_current;

	for ( int j = 0; j < 256; j++ )	// loop through all maps
	{
		if ( !g_MapList.m_maps[j] ) continue;		// skip unsupported maps

		for ( int i = 0; i < g_MapList.GetSectorQty(j); i++ )
		{
			CSector * pSector = g_World.GetSector(j, i);
			ASSERT(pSector);
			CChar * pCharNext;
			CChar * pChar = STATIC_CAST <CChar*>( pSector->m_Chars_Active.GetHead());
			for ( ; pChar!=NULL; pChar = pCharNext )
			{
				pCharNext = pChar->GetNext();
				if ( pChar->NPC_IsSpawnedBy( this ))
				{
					pChar->Delete();
					iCurrent --;
				}
			}
		}
	}
	if (iCurrent && ! g_Serv.IsLoading())
	{
		DEBUG_CHECK(iCurrent==0);
	}
	m_itSpawnChar.m_current = 0;	// Should not be necessary
	Spawn_OnTick( false );
}
示例#2
0
int secp256k1_ecdsa_verify(const secp256k1_context_t* ctx, const unsigned char *msg32, const unsigned char *sig, int siglen, const unsigned char *pubkey, int pubkeylen) {
    secp256k1_ge_t q;
    secp256k1_ecdsa_sig_t s;
    secp256k1_scalar_t m;
    int ret = -3;
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
    DEBUG_CHECK(msg32 != NULL);
    DEBUG_CHECK(sig != NULL);
    DEBUG_CHECK(pubkey != NULL);

    secp256k1_scalar_set_b32(&m, msg32, NULL);

    if (secp256k1_eckey_pubkey_parse(&q, pubkey, pubkeylen)) {
        if (secp256k1_ecdsa_sig_parse(&s, sig, siglen)) {
            if (secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &s, &q, &m)) {
                /* success is 1, all other values are fail */
                ret = 1;
            } else {
                ret = 0;
            }
        } else {
            ret = -2;
        }
    } else {
        ret = -1;
    }

    return ret;
}
示例#3
0
int secp256k1_ec_pubkey_tweak_mul(const secp256k1_context_t* ctx, unsigned char *pubkey, int pubkeylen, const unsigned char *tweak) {
    secp256k1_ge_t p;
    secp256k1_scalar_t factor;
    int ret = 0;
    int overflow = 0;
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(secp256k1_ecmult_context_is_built(&ctx->ecmult_ctx));
    DEBUG_CHECK(pubkey != NULL);
    DEBUG_CHECK(tweak != NULL);

    secp256k1_scalar_set_b32(&factor, tweak, &overflow);
    if (!overflow) {
        ret = secp256k1_eckey_pubkey_parse(&p, pubkey, pubkeylen);
        if (ret) {
            ret = secp256k1_eckey_pubkey_tweak_mul(&ctx->ecmult_ctx, &p, &factor);
        }
        if (ret) {
            int oldlen = pubkeylen;
            ret = secp256k1_eckey_pubkey_serialize(&p, pubkey, &pubkeylen, oldlen <= 33);
            VERIFY_CHECK(pubkeylen == oldlen);
        }
    }

    return ret;
}
示例#4
0
int secp256k1_ecdsa_pubkey_tweak_mul(unsigned char *pubkey, int pubkeylen, const unsigned char *tweak) {
    DEBUG_CHECK(secp256k1_ecmult_consts != NULL);
    DEBUG_CHECK(pubkey != NULL);
    DEBUG_CHECK(tweak != NULL);

    int ret = 1;
    secp256k1_num_t factor;
    secp256k1_num_init(&factor);
    secp256k1_num_set_bin(&factor, tweak, 32);
    if (secp256k1_num_is_zero(&factor))
        ret = 0;
    if (secp256k1_num_cmp(&factor, &secp256k1_ge_consts->order) >= 0)
        ret = 0;
    secp256k1_ge_t p;
    if (ret) {
        if (!secp256k1_ecdsa_pubkey_parse(&p, pubkey, pubkeylen))
            ret = 0;
    }
    if (ret) {
        secp256k1_num_t zero;
        secp256k1_num_init(&zero);
        secp256k1_num_set_int(&zero, 0);
        secp256k1_gej_t pt;
        secp256k1_gej_set_ge(&pt, &p);
        secp256k1_ecmult(&pt, &pt, &factor, &zero);
        secp256k1_num_free(&zero);
        secp256k1_ge_set_gej(&p, &pt);
        int oldlen = pubkeylen;
        secp256k1_ecdsa_pubkey_serialize(&p, pubkey, &pubkeylen, oldlen <= 33);
        VERIFY_CHECK(pubkeylen == oldlen);
    }
    secp256k1_num_free(&factor);
    return ret;
}
示例#5
0
int secp256k1_ecdsa_verify(const unsigned char *msg, int msglen, const unsigned char *sig, int siglen, const unsigned char *pubkey, int pubkeylen) {
    DEBUG_CHECK(secp256k1_ecmult_consts != NULL);
    DEBUG_CHECK(msg != NULL);
    DEBUG_CHECK(msglen <= 32);
    DEBUG_CHECK(sig != NULL);
    DEBUG_CHECK(pubkey != NULL);

    int ret = -3;
    secp256k1_num_t m; 
    secp256k1_num_init(&m);
    secp256k1_ecdsa_sig_t s;
    secp256k1_ecdsa_sig_init(&s);
    secp256k1_ge_t q;
    secp256k1_num_set_bin(&m, msg, msglen);

    if (!secp256k1_ecdsa_pubkey_parse(&q, pubkey, pubkeylen)) {
        ret = -1;
        goto end;
    }
    if (!secp256k1_ecdsa_sig_parse(&s, sig, siglen)) {
        ret = -2;
        goto end;
    }
    if (!secp256k1_ecdsa_sig_verify(&s, &q, &m)) {
        ret = 0;
        goto end;
    }
    ret = 1;
end:
    secp256k1_ecdsa_sig_free(&s);
    secp256k1_num_free(&m);
    return ret;
}
示例#6
0
int secp256k1_ecdsa_privkey_tweak_add(unsigned char *seckey, const unsigned char *tweak) {
    DEBUG_CHECK(seckey != NULL);
    DEBUG_CHECK(tweak != NULL);

    int ret = 1;
    secp256k1_num_t term;
    secp256k1_num_init(&term);
    secp256k1_num_set_bin(&term, tweak, 32);
    if (secp256k1_num_cmp(&term, &secp256k1_ge_consts->order) >= 0)
        ret = 0;
    secp256k1_num_t sec;
    secp256k1_num_init(&sec);
    if (ret) {
        secp256k1_num_set_bin(&sec, seckey, 32);
        secp256k1_num_add(&sec, &sec, &term);
        secp256k1_num_mod(&sec, &secp256k1_ge_consts->order);
        if (secp256k1_num_is_zero(&sec))
            ret = 0;
    }
    if (ret)
        secp256k1_num_get_bin(seckey, 32, &sec);
    secp256k1_num_clear(&sec);
    secp256k1_num_clear(&term);
    secp256k1_num_free(&sec);
    secp256k1_num_free(&term);
    return ret;
}
示例#7
0
int secp256k1_ecdsa_pubkey_tweak_add(unsigned char *pubkey, int pubkeylen, const unsigned char *tweak) {
    DEBUG_CHECK(secp256k1_ecmult_consts != NULL);
    DEBUG_CHECK(pubkey != NULL);
    DEBUG_CHECK(tweak != NULL);

    int ret = 1;
    secp256k1_num_t term;
    secp256k1_num_init(&term);
    secp256k1_num_set_bin(&term, tweak, 32);
    if (secp256k1_num_cmp(&term, &secp256k1_ge_consts->order) >= 0)
        ret = 0;
    secp256k1_ge_t p;
    if (ret) {
        if (!secp256k1_ecdsa_pubkey_parse(&p, pubkey, pubkeylen))
            ret = 0;
    }
    if (ret) {
        secp256k1_gej_t pt;
        secp256k1_gej_set_ge(&pt, &p);
        secp256k1_num_t one;
        secp256k1_num_init(&one);
        secp256k1_num_set_int(&one, 1);
        secp256k1_ecmult(&pt, &pt, &one, &term);
        secp256k1_num_free(&one);
        if (secp256k1_gej_is_infinity(&pt))
            ret = 0;
        secp256k1_ge_set_gej(&p, &pt);
        int oldlen = pubkeylen;
        secp256k1_ecdsa_pubkey_serialize(&p, pubkey, &pubkeylen, oldlen <= 33);
        VERIFY_CHECK(pubkeylen == oldlen);
    }
    secp256k1_num_free(&term);
    return ret;
}
示例#8
0
文件: db.c 项目: BPotato/fluffos
void free_db_conn (db_t * db)
{
	DEBUG_CHECK(db->flags & DB_FLAG_EMPTY, "Freeing DB connection that is already freed\n");
	DEBUG_CHECK(!dbConnUsed, "Freeing DB connection when dbConnUsed == 0\n");
	dbConnUsed--;
	db->flags |= DB_FLAG_EMPTY;
}
示例#9
0
文件: swap.c 项目: xcw0579/mudOS
/*
 * Read something back in from swap.  Return the size.
 *   blockp    - a pointer to what will hold the block read in
 *   loc       - position in the swap file to read from
 */
static int
swap_in(char **  blockp, int  loc)
{
    int size;

    DEBUG_CHECK(!blockp, "blockp null in swap_in()\n");
    
    if (loc == -1)
	return 0;
    swap_seek(loc, 0);
#ifdef SWAP_USE_FD
    /* find out size */
    if (read(swap_file, &size, sizeof size) == -1)
        fatal("Couldn't read the swap file.\n");
    DEBUG_CHECK(size <= 0, "Illegal size read from swap file.\n");
    *blockp = DXALLOC(size, TAG_SWAP, "swap_in");
    if (read(swap_file, *blockp, size) == -1)
        fatal("Couldn't read the swap file.\n");
#else
    /* find out size */
    if (fread((char *) &size, sizeof size, 1, swap_file) == -1)
	fatal("Couldn't read the swap file.\n");
    DEBUG_CHECK(size <= 0, "Illegal size read from swap file.\n");
    *blockp = DXALLOC(size, TAG_SWAP, "swap_in");
    if (fread(*blockp, size, 1, swap_file) == -1)
	fatal("Couldn't read the swap file.\n");
#endif
    total_bytes_swapped -= size;
    return size;
}
示例#10
0
int secp256k1_ec_pubkey_verify(const secp256k1_context_t* ctx, const unsigned char *pubkey, int pubkeylen) {
    secp256k1_ge_t q;
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(pubkey != NULL);
    (void)ctx;

    return secp256k1_eckey_pubkey_parse(&q, pubkey, pubkeylen);
}
示例#11
0
int secp256k1_ecdsa_pubkey_compress(unsigned char *pubkey, int *pubkeylen) {
    DEBUG_CHECK(pubkey != NULL);
    DEBUG_CHECK(pubkeylen != NULL);

    secp256k1_ge_t p;
    if (!secp256k1_ecdsa_pubkey_parse(&p, pubkey, *pubkeylen))
        return 0;
    secp256k1_ecdsa_pubkey_serialize(&p, pubkey, pubkeylen, 1);
    return 1;
}
示例#12
0
int secp256k1_ecdsa_privkey_import(unsigned char *seckey, const unsigned char *privkey, int privkeylen) {
    DEBUG_CHECK(seckey != NULL);
    DEBUG_CHECK(privkey != NULL);

    secp256k1_num_t key;
    secp256k1_num_init(&key);
    int ret = secp256k1_ecdsa_privkey_parse(&key, privkey, privkeylen);
    if (ret)
        secp256k1_num_get_bin(seckey, 32, &key);
    secp256k1_num_free(&key);
    return ret;
}
示例#13
0
int secp256k1_ecdsa_privkey_export(const unsigned char *seckey, unsigned char *privkey, int *privkeylen, int compressed) {
    DEBUG_CHECK(seckey != NULL);
    DEBUG_CHECK(privkey != NULL);
    DEBUG_CHECK(privkeylen != NULL);

    secp256k1_num_t key;
    secp256k1_num_init(&key);
    secp256k1_num_set_bin(&key, seckey, 32);
    int ret = secp256k1_ecdsa_privkey_serialize(privkey, privkeylen, &key, compressed);
    secp256k1_num_free(&key);
    return ret;
}
示例#14
0
/*
This function reads images in to a vector.  That vector is then mean subtracted
and then projected onto an optimal basis (PCA, LDA or LPP). Returned is a matrix
that contains the images after they have been projected onto the subspace.
*/
Matrix
readAndProjectImages (Subspace *s, char *imageNamesFile, char *imageDirectory, int *numImages, ImageList **srt)
{
    int i, j;
    Matrix images, vector, smallVector;
    char name[FILE_LINE_LENGTH];
    ImageList *subject, *replicate;

    DEBUG(1, "Reading training file names from file");

    *srt = getImageNames(imageNamesFile, numImages);

    DEBUG_CHECK(*srt, "Error: header no imagenames found in file image list file");

    /* Automatically determine number of pixels in images    */
    sprintf(name, "%s/%s", imageDirectory, (*srt)->filename);
    DEBUG(1, "Autodetecting number of pixels, i.e. vector length based on the size of image 0.");
    DEBUG_CHECK (autoFileLength(name) == s->numPixels, "Images sizes do not match subspace basis vector size");
    DEBUG_INT(1, "Vector length", s->numPixels);
    DEBUG_CHECK(s->numPixels > 0, "Error positive value required for a Vector Length");

    /*Images stored in the columns of a matrix */
    DEBUG(1, "Allocating image matrix");

    images = makeMatrix(s->basis->col_dim, *numImages);
    vector = makeMatrix(s->numPixels, 1);

    i = 0;
    for (subject = *srt; subject; subject = subject->next_subject) {
        for (replicate = subject; replicate; replicate = replicate->next_replicate) {
            if (debuglevel > 0)
                printf("%s ", replicate->filename);
            sprintf(name, "%s/%s", imageDirectory, replicate->filename);
            replicate->imageIndex = i;
            readFile(name, 0, vector);

            writeProgress("Reading images", i,*numImages);

            smallVector = centerThenProjectImages(s, vector);

            /* Copy the smaller vector into the image matrix*/
            for (j = 0; j < smallVector->row_dim; j++) {
                ME(images, j, i) = ME(smallVector, j, 0);
            }
            freeMatrix(smallVector);
            i++;  /* increament the image index */
        }
        if (debuglevel > 0)
            printf("\n");
    }

    return images;
}
示例#15
0
int secp256k1_ec_pubkey_decompress(const secp256k1_context_t* ctx, unsigned char *pubkey, int *pubkeylen) {
    secp256k1_ge_t p;
    int ret = 0;
    DEBUG_CHECK(pubkey != NULL);
    DEBUG_CHECK(pubkeylen != NULL);
    (void)ctx;

    if (secp256k1_eckey_pubkey_parse(&p, pubkey, *pubkeylen)) {
        ret = secp256k1_eckey_pubkey_serialize(&p, pubkey, pubkeylen, 0);
    }
    return ret;
}
示例#16
0
int secp256k1_ec_seckey_verify(const secp256k1_context_t* ctx, const unsigned char *seckey) {
    secp256k1_scalar_t sec;
    int ret;
    int overflow;
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(seckey != NULL);
    (void)ctx;

    secp256k1_scalar_set_b32(&sec, seckey, &overflow);
    ret = !secp256k1_scalar_is_zero(&sec) && !overflow;
    secp256k1_scalar_clear(&sec);
    return ret;
}
示例#17
0
int secp256k1_ec_privkey_import(const secp256k1_context_t* ctx, unsigned char *seckey, const unsigned char *privkey, int privkeylen) {
    secp256k1_scalar_t key;
    int ret = 0;
    DEBUG_CHECK(seckey != NULL);
    DEBUG_CHECK(privkey != NULL);
    (void)ctx;

    ret = secp256k1_eckey_privkey_parse(&key, privkey, privkeylen);
    if (ret) {
        secp256k1_scalar_get_b32(seckey, &key);
    }
    secp256k1_scalar_clear(&key);
    return ret;
}
示例#18
0
int secp256k1_ec_privkey_export(const secp256k1_context_t* ctx, const unsigned char *seckey, unsigned char *privkey, int *privkeylen, int compressed) {
    secp256k1_scalar_t key;
    int ret = 0;
    DEBUG_CHECK(seckey != NULL);
    DEBUG_CHECK(privkey != NULL);
    DEBUG_CHECK(privkeylen != NULL);
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));

    secp256k1_scalar_set_b32(&key, seckey, NULL);
    ret = secp256k1_eckey_privkey_serialize(&ctx->ecmult_gen_ctx, privkey, privkeylen, &key, compressed);
    secp256k1_scalar_clear(&key);
    return ret;
}
示例#19
0
bool CItem::Ship_Plank( bool fOpen )
{
	// IT_SHIP_PLANK to IT_SHIP_SIDE and IT_SHIP_SIDE_LOCKED
	// This item is the ships plank.

	CItemBase * pItemDef = Item_GetDef();
	ITEMID_TYPE idState = (ITEMID_TYPE) RES_GET_INDEX( pItemDef->m_ttShipPlank.m_idState );
	if ( ! idState )
	{
		// Broken ?
		return( false );
	}
	if ( IsType(IT_SHIP_PLANK))
	{
		if ( fOpen )
			return( true );
	}
	else
	{
		DEBUG_CHECK( IsType(IT_SHIP_SIDE) || IsType(IT_SHIP_SIDE_LOCKED));
		if ( ! fOpen )
			return( true );
	}

	SetID( idState );
	Update();
	return( true );
}
示例#20
0
bool ResourcePack::IsCorrectState()
{
	DEBUG_CHECK(minerals >= 0 && gas >= 0 && supply >= 0);
	if (minerals >= 0 && gas >= 0 && supply >= 0)
		return true;
	return false;
}
示例#21
0
文件: cfuns.c 项目: xcw0579/mudOS
void c_return_zero() {
    pop_n_elems(csp->num_local_variables);
    sp++;
    DEBUG_CHECK(sp != fp, "Bad stack at c_return\n");
    *sp = const0;
    pop_control_stack();
}
示例#22
0
文件: cfuns.c 项目: xcw0579/mudOS
void c_call(int  func, int  num_arg) {
    function_t *funp;
    
    func += function_index_offset;
    /*
     * Find the function in the function table. As the
     * function may have been redefined by inheritance, we
     * must look in the last table, which is pointed to by
     * current_object.
     */
    DEBUG_CHECK(func >= current_object->prog->last_inherited +
		current_object->prog->num_functions_defined,
		"Illegal function index\n");
    
    if (current_object->prog->function_flags[func] & FUNC_UNDEFINED)
	error("Undefined function: %s\n", function_name(current_object->prog, func));
    /* Save all important global stack machine registers */
    push_control_stack(FRAME_FUNCTION);
    
    caller_type = ORIGIN_LOCAL;
    /* This assigment must be done after push_control_stack() */
    current_prog = current_object->prog;
    /*
     * If it is an inherited function, search for the real
     * definition.
     */
    csp->num_local_variables = num_arg + num_varargs;
    num_varargs = 0;
    funp = setup_new_frame(func);
    csp->pc = pc;	/* The corrected return address */
    call_program(current_prog, funp->address);
}
示例#23
0
文件: master.c 项目: xcw0579/mudOS
/* Note that now, once the master object loads once, there is ALWAYS a
 * master object, so the only way this can fail is if the master object
 * hasn't loaded yet.  In that case, we return (svalue_t *)-1, and the
 * calling routine should let the check succeed. 失败只可能是还没有load进master
  这像是在让master调用函数?   */
svalue_t *apply_master_ob(int  fun, int  num_arg)	/* 将master应用起来? */
{
    if (!master_ob) {
        pop_n_elems(num_arg);	/* 只要master还没有load进来,就将栈清空? */
        return (svalue_t *)-1;
    }

    if (master_applies[fun].func) {		/* 这里会调用不同的函数,函数都在里边? */
#ifdef TRACE
        if (TRACEP(TRACE_APPLY)) {
            do_trace("master apply", master_applies[fun].func->name, "\n");
        }
#endif
        DEBUG_CHECK(master_ob->flags & O_SWAPPED, "Master object swapped!\n");

        call_direct(master_ob, master_applies[fun].index, ORIGIN_DRIVER, num_arg);	/* 像是在调用函数? */

        free_svalue(&apply_ret_value, "apply_master_ob");
        apply_ret_value = *sp--;		/* 从栈中取出返回值 */
        return &apply_ret_value;
    } else {
        pop_n_elems(num_arg);
        return 0;
    }
}
示例#24
0
bool isBasicLatinLetter(uint32_t cp) {
  // 0-31: misc whitespace chars, hex tablet things

  // 33-64: misc punc, digits, more misc punc
  // 33 = '!''
  // 54 = '6'
  // 64 = '@'

  if (cp <= 64) {
    return false;
  }
  if (cp <= 96 && cp > 90) {
    // lbracket, backslash, etc
    return false;
  }

  // 122 = 'z'
  if (cp > 122) {
    DEBUG_CHECK(cp <= 127);
    return false;
  }

  // remaining characters are letters
  return true;
}
示例#25
0
/**
* Reads a FERET nrm file
*
* @param fn Filename
* @param numpix Number of pixels to read
* @returns An malloc'd array of floats
*/
float *readFeretRaster(const char *fn,  int numpix)
{
    FILE *fp;
    float* data;

    fp = fopen(fn, "rb");
    if (fp == NULL)
    {
        fprintf (stderr, "failed to open %s", fn);
        exit(0);
    }

    data = (float*)malloc(sizeof(float)*numpix);
    DEBUG_CHECK (data, "malloc failed");

    if (!fread(data, sizeof(float), numpix, fp))
    {
        fprintf (stderr, "fread in readFeretRaster failed");
        exit(0);
    }

    if (isMachineLittleEndian()) byteswap_4(data, numpix);

    fclose(fp);
    return data;
}
示例#26
0
/**
* Reads all of the names in a file into an array of
* strings. Each element of the array is a char pointer.
*
* If nStrings is non-NULL, the number of strings is
* returned in nStrings.
*
* The array is always one larger than nStrings elements
* long and the last element is a NULL.
*
* @param fileName Name of file to read
* @param nStrings Optional pointer to integer that will on return contain
*                 the count of strings read from the file
* @returns A NULL-terminated list of NULL-terminated strings
*/
ListOfStrings
readListOfStrings (const char *fileName, int *nStrings)
{
    Tokenizer tok;
    void *stringList = NULL;
    FILE *f;
    char *string;
    ListOfStrings array;
    size_t numStrings;

    f = fopen (fileName, "r");
    DEBUG_CHECK (f, "Unable to read file");

    tokenizerInit (&tok, tokenizerStreamReader, f);
    while (!tokenizerEndOfFile (&tok))
    {
        string = strdup (tokenizerGetWord (&tok));
        listAccumulate (&stringList, &string, sizeof (unsigned char *));
    }

    fclose (f);

    /* Add a terminating NULL */
    string = NULL;
    listAccumulate (&stringList, &string, sizeof (unsigned char *));

    array = (ListOfStrings)listToArray (&stringList, sizeof (unsigned char *), &numStrings);
    if (nStrings) *nStrings = numStrings - 1; /* Don't count the NULL */
    return array;
}
示例#27
0
/* nonstatic, is used in mappings too */
int sameval P2(svalue_t *, arg1, svalue_t *, arg2)
{
    DEBUG_CHECK(!arg1 || !arg2, "Null pointer passed to sameval.\n");

    switch (arg1->type | arg2->type) {
    case T_NUMBER:
	return arg1->u.number == arg2->u.number;
    case T_ARRAY:
    case T_CLASS:
	return arg1->u.arr == arg2->u.arr;
    case T_STRING:
	if (SVALUE_STRLEN_DIFFERS(arg1, arg2)) return 0;
	return !strcmp(arg1->u.string, arg2->u.string);
    case T_OBJECT:
	return arg1->u.ob == arg2->u.ob;
    case T_MAPPING:
	return arg1->u.map == arg2->u.map;
    case T_FUNCTION:
	return arg1->u.fp == arg2->u.fp;
    case T_REAL:
	return arg1->u.real == arg2->u.real;
    case T_BUFFER:
	return arg1->u.buf == arg2->u.buf;
    }
    return 0;
}
示例#28
0
/* invert a matrix using Gaussian Elimination */
Matrix invertRREF(Matrix m) {
    int prealloc = alloc_matrix;
    int i,j;
    Matrix tmp = makeZeroMatrix(m->row_dim, m->col_dim*2);
    Matrix inverse = makeMatrix(m->row_dim, m->col_dim);
    DEBUG_CHECK(m->row_dim == m->col_dim,"Matrix can only be inverted if it is square");
    /* build the tmp Matrix which will be passed to RREF */
    for( i = 0; i < m->row_dim; i++) {
        for( j = 0; j < m->col_dim; j++) {
            ME(tmp,i,j) = ME(m,i,j);
            if(i == j) {
                ME(tmp,i,j+m->col_dim) = 1;
            }
        }
    }
    matrixRREF(tmp);

    for( i = 0; i < m->row_dim; i++) {
        for( j = 0; j < m->col_dim; j++) {
            ME(inverse,i,j) = ME(tmp,i,j+m->col_dim);
        }
    }

    freeMatrix(tmp);

    if(prealloc != alloc_matrix - 1) {
        printf("Error deallocating matricies <%s>: pre=%d post=%d",__FUNCTION__, prealloc, alloc_matrix);
        exit(1);
    }
    return inverse;
}
示例#29
0
int secp256k1_ecdsa_sign_compact(const secp256k1_context_t* ctx, const unsigned char *msg32, unsigned char *sig64, const unsigned char *seckey, secp256k1_nonce_function_t noncefp, const void* noncedata, int *recid) {
    secp256k1_ecdsa_sig_t sig;
    secp256k1_scalar_t sec, non, msg;
    int ret = 0;
    int overflow = 0;
    unsigned int count = 0;
    DEBUG_CHECK(ctx != NULL);
    DEBUG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));
    DEBUG_CHECK(msg32 != NULL);
    DEBUG_CHECK(sig64 != NULL);
    DEBUG_CHECK(seckey != NULL);
    if (noncefp == NULL) {
        noncefp = secp256k1_nonce_function_default;
    }

    secp256k1_scalar_set_b32(&sec, seckey, &overflow);
    /* Fail if the secret key is invalid. */
    if (!overflow && !secp256k1_scalar_is_zero(&sec)) {
        secp256k1_scalar_set_b32(&msg, msg32, NULL);
        while (1) {
            unsigned char nonce32[32];
            ret = noncefp(nonce32, msg32, seckey, count, noncedata);
            if (!ret) {
                break;
            }
            secp256k1_scalar_set_b32(&non, nonce32, &overflow);
            memset(nonce32, 0, 32);
            if (!secp256k1_scalar_is_zero(&non) && !overflow) {
                if (secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, &sig, &sec, &msg, &non, recid)) {
                    break;
                }
            }
            count++;
        }
        if (ret) {
            secp256k1_scalar_get_b32(sig64, &sig.r);
            secp256k1_scalar_get_b32(sig64 + 32, &sig.s);
        }
        secp256k1_scalar_clear(&msg);
        secp256k1_scalar_clear(&non);
        secp256k1_scalar_clear(&sec);
    }
    if (!ret) {
        memset(sig64, 0, 64);
    }
    return ret;
}
示例#30
0
文件: cfuns.c 项目: xcw0579/mudOS
void c_foreach(int  flags, int  idx1, int  idx2) {
    IF_DEBUG(stack_in_use_as_temporary++);
    
    if (flags & FOREACH_MAPPING) {
	CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH);
	
	push_refed_array(mapping_indices(sp->u.map));

	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
		    
	STACK_INC;
	sp->type = T_LVALUE;
	if (flags & FOREACH_LEFT_GLOBAL) {
	    sp->u.lvalue = &current_object->variables[idx1 + variable_index_offset];
	} else {
	    sp->u.lvalue = fp + idx1;
	}
    } else 
    if (sp->type == T_STRING) {
	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string);
	sp->subtype = SVALUE_STRLEN(sp - 1);
    } else {
	CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH);

	STACK_INC;
	sp->type = T_NUMBER;
	sp->u.lvalue = (sp-1)->u.arr->item;
	sp->subtype = (sp-1)->u.arr->size;
    }

    if (flags & FOREACH_RIGHT_GLOBAL) {
	STACK_INC;
	sp->type = T_LVALUE;
	sp->u.lvalue = &current_object->variables[idx2 + variable_index_offset];
    } else if (flags & FOREACH_REF) {
	ref_t *ref = make_ref();
	svalue_t *loc = fp + idx2;

	/* foreach guarantees our target remains valid */
	ref->lvalue = 0;
	ref->sv.type = T_NUMBER;
	STACK_INC;
	sp->type = T_REF;
	sp->u.ref = ref;
	DEBUG_CHECK(loc->type != T_NUMBER && loc->type != T_REF, "Somehow a reference in foreach acquired a value before coming into scope");
	loc->type = T_REF;
	loc->u.ref = ref;
	ref->ref++;
    } else {
	STACK_INC;
	sp->type = T_LVALUE;
	sp->u.lvalue = fp + idx2;
    }
}