void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
    TR_ASSERT(handle != NULL);
    TR_ASSERT(key != NULL);

    API(Arc4SetKey)(handle, key, key_length);
}
Example #2
0
void t0 (ComplexI sz)
{
     char * name = "../IM_CAD/MOUSSAN_AA/Moussan_AA.tif";

     EL_API_VECTO::ParamSkel     PSkel;
     EL_API_VECTO::ParamApprox   PApp;

     EL_API_VECTO  API(PSkel,PApp,20);

     EL_API_VECTO::ParamFile PFile(name,false);


     int x,y;
     scanf("%d %d",&x,&y);

     MyVectoAct MVA; 

     API.vecto
     (
          PFile,
          MVA,
          ComplexI(x,y),
          sz
     );
}
Example #3
0
int32_t nvram_set(char * section, char * key, char * value)
{
    API();
    if (OK == _nvram_buf_set(section, key, value))
        return nvram_commit(0);
    return NG;
}
Example #4
0
int32_t nvram_show(char * section)
{
    int32_t i = 0, j = 0, counter = 0;
    API();
    for (i=0; i<sectionnum; i++)
    {
        if (nvramcache[i].flag & NV_IV) // skip invisible section
            continue;
        if (section && 0 != strcmp(section, nvramcache[i].name))
            continue;

        printf("\n\n++++++++++++ %s ++++++++++++ 0x%x\n", nvramcache[i].name, nvramcache[i].flag);
        counter = 0;
        for (j=0; j<MAX_ENTRY; j++)
        {
            if (nvramcache[i].cache[j].name)
            {
                counter++;
                printf("%s=%s\n",nvramcache[i].cache[j].name, nvramcache[i].cache[j].value);
            }
        }
        printf("++++++++++++ %s ++++++++++++ %d\n", nvramcache[i].name, counter);
    }
    return OK;
}
Example #5
0
int32_t nvram_filecache(char * defile)
{
    int32_t rc = OK;
    FILE * fp = NULL;
    struct stat statbuf;
    char * buffer = NULL;

    API();

    /* create a cache file */
    rc = stat(defile, &statbuf);
    if (!rc)
    {
        DEBUG("cache file %s is ready.\n", defile);
        return OK;
    }


    fp = fopen(defile, "w+b");
    if (!fp)
    {
        DEBUG("failed to create %s, %s, %s\n",
            defile, strerror(errno), __FUNCTION__);
        return NG;
    }
    DEBUG("cache file %s, created.\n", defile);

    buffer = (char *)malloc(nvram_mtd_size);
    if(!buffer)
    {
        DEBUG("failed to alloc %d bytes for , %s, %s\n",
            nvram_mtd_size, defile, __FUNCTION__);
        fclose(fp);
        return NG;
    }

    /* dump "Config" partition into a cache file. */
    memset(buffer, 0, nvram_mtd_size);

    DEBUG("read original data from flash.\n");
    if (flash_read(buffer,0,nvram_mtd_size) < 0)
    {
        fclose(fp);
        return NG;
    }

    //dump(buffer, nvram_mtd_size, 0);

    DEBUG("write into cache file.\n");
    rc = fwrite(buffer, 1, nvram_mtd_size, fp);
    if (rc != nvram_mtd_size)
    {
        DEBUG("failed to write data into %s, %s, %s\n",
            defile, strerror(errno), __FUNCTION__);
        return NG;
    }
    fclose(fp);
    return OK;
}
Example #6
0
int32_t nvram_del(char * section, char * key)
{
    API();

    if (OK == _nvram_buf_del(section, key))
        return nvram_commit(0);
    return NG;
}
Example #7
0
int32_t nvram_reset(char * section, char * defile)
{
    API();

    if (OK == nvram_parse(section, defile))
        return nvram_commit(1);

    return NG;
}
Example #8
0
Filtro::Filtro(cv::Mat pImagen, int pN, int pM) {
    aN = pN; //filas
    aM = pM; //columnas
    cv::Mat Matrix1(pN,pM,CV_8UC1);
    cv::Mat Matrix2(pN,pM,CV_8UC1);
    cvtColor(pImagen,Matrix1,CV_RGB2GRAY);
    aMatrix1 = Matrix1;
    aMatrix2 = Matrix2;
    aAPI = API();
}
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
    size_t generator_num_length)
{
    struct tr_dh_ctx* handle = tr_new0(struct tr_dh_ctx, 1);

    TR_ASSERT(prime_num != NULL);
    TR_ASSERT(generator_num != NULL);

    API(InitDhKey)(&handle->dh);

    if (!check_result(API(DhSetKey)(&handle->dh, prime_num, prime_num_length, generator_num, generator_num_length)))
    {
        tr_free(handle);
        return NULL;
    }

    handle->key_length = prime_num_length;

    return handle;
}
Example #10
0
int usb_open(struct usb *usb)
{
	int (*rom_get_per_driver)(struct per_driver **io, u32 device_type);
	int (*rom_get_per_device)(struct per_handle **rh);
	struct per_handle *boot;
	int n;
        u32 base;

	memset(usb, 0, sizeof(*usb));


        if (get_omap_rev() >= OMAP_4460_ES1_DOT_0)
                base = PUBLIC_API_BASE_4460;
        else
                base = PUBLIC_API_BASE_4430;

	rom_get_per_driver = API(base + PUBLIC_GET_DRIVER_PER_OFFSET);
	rom_get_per_device = API(base + PUBLIC_GET_DEVICE_PER_OFFSET);

	n = rom_get_per_device(&boot);
	if (n)
		return n;

	if ((boot->device_type != DEVICE_USB) &&
	    (boot->device_type != DEVICE_USBEXT))
		return -1;

	n = rom_get_per_driver(&usb->io, boot->device_type);
	if (n)
		return n;

	usb->dread.xfer_mode = boot->xfer_mode;
	usb->dread.options = boot->options;
	usb->dread.device_type = boot->device_type;

	usb->dwrite.xfer_mode = boot->xfer_mode;
	usb->dwrite.options = boot->options;
	usb->dwrite.device_type = boot->device_type;

	return 0;
}
Example #11
0
tr_sha1_ctx_t tr_sha1_init(void)
{
    Sha* handle = tr_new(Sha, 1);

    if (check_result(API(InitSha)(handle)))
    {
        return handle;
    }

    tr_free(handle);
    return NULL;
}
Example #12
0
bool tr_rand_buffer(void* buffer, size_t length)
{
    bool ret;
    tr_lock* rng_lock = get_rng_lock();

    TR_ASSERT(buffer != NULL);

    tr_lockLock(rng_lock);
    ret = check_result(API(RNG_GenerateBlock)(get_rng(), buffer, length));
    tr_lockUnlock(rng_lock);

    return ret;
}
Example #13
0
void tr_dh_free(tr_dh_ctx_t raw_handle)
{
    struct tr_dh_ctx* handle = raw_handle;

    if (handle == NULL)
    {
        return;
    }

    API(FreeDhKey)(&handle->dh);
    tr_free(handle->private_key);
    tr_free(handle);
}
Example #14
0
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
    TR_ASSERT(handle != NULL);

    if (data_length == 0)
    {
        return true;
    }

    TR_ASSERT(data != NULL);

    return check_result(API(ShaUpdate)(handle, data, data_length));
}
Example #15
0
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
    TR_ASSERT(handle != NULL);

    if (length == 0)
    {
        return;
    }

    TR_ASSERT(input != NULL);
    TR_ASSERT(output != NULL);

    API(Arc4Process)(handle, output, input, length);
}
Example #16
0
bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
{
    bool ret = true;

    if (hash != NULL)
    {
        TR_ASSERT(handle != NULL);

        ret = check_result(API(ShaFinal)(handle, hash));
    }

    tr_free(handle);
    return ret;
}
Example #17
0
int32_t nvram_clear(char * section)
{
    int32_t i = 0;
    FILE * fp = NULL;
    section_t * sec = NULL;
    char * buffer = NULL;

    API();

    fp = fopen(NVRAM_CACHE_FILE, "r+b");
    if (!fp)
    {
        DEBUG("failed to create %s, %s, %s\n", NVRAM_CACHE_FILE, strerror(errno), __FUNCTION__);
        return NG;
    }

    sec = _nvram_section(section);
    if(!sec || (sec->flag & NV_RO))
    {
        DEBUG("invalid section!\n");
        return NG;
    }

    fseek(fp, sec->offset, SEEK_SET);

    buffer = (char *)malloc(sec->size);
    if(!buffer)
    {
        DEBUG("failed to alloc buffer (%d) for nvram! %s.\n", sec->size, __FUNCTION__);
        fclose(fp);
        return NG;
    }
    memset(buffer, 0, sec->size);

    if(strcmp(sec->name,"uboot") == 0)
        sec->crc =
            crc32(0, (uint8_t *)(buffer+4), sec->size-4);
    else
        sec->crc =
            crc32(0, (uint8_t *)(buffer+5), sec->size-5);
    *(uint32_t *)(buffer) = sec->crc;

    i = fwrite(buffer, sec->size, 1, fp);
    ASSERT(i == 1);

    fclose(fp);
    return OK;
}
Example #18
0
static void log_cyassl_error(int error_code, char const* file, int line)
{
    if (tr_logLevelIsActive(TR_LOG_ERROR))
    {
#if API_VERSION_HEX >= 0x03004000
        char const* error_message = API(GetErrorString)(error_code);
#elif API_VERSION_HEX >= 0x03000002
        char const* error_message = CTaoCryptGetErrorString(error_code);
#else
        char error_message[CYASSL_MAX_ERROR_SZ];
        CTaoCryptErrorString(error_code, error_message);
#endif

        tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "CyaSSL error: %s", error_message);
    }
}
Example #19
0
int32_t nvram_show(char * section)
{
    int32_t i = 0, j = 0;
    API();
    for (i=0; i<sectionnum; i++)
    {
        if (section && 0 != strcmp(section, nvramcache[i].name))
            continue;
        for (j=0; j<MAX_ENTRY; j++)
        {
            if (nvramcache[i].cache[j].name)
                printf("%s=%s\n",nvramcache[i].cache[j].name, nvramcache[i].cache[j].value);
        }
    }
    return OK;
}
Example #20
0
static RNG* get_rng(void)
{
    static RNG rng;
    static bool rng_initialized = false;

    if (!rng_initialized)
    {
        if (!check_result(API(InitRng)(&rng)))
        {
            return NULL;
        }

        rng_initialized = true;
    }

    return &rng;
}
Example #21
0
int load_image(unsigned device, unsigned start, unsigned count, void *data)
{
	int (*rom_get_mem_driver)(struct mem_driver **io, u32 type);
	struct mem_driver *io = 0;
	struct mem_device local_md_device, *md = 0;
	struct read_desc rd;
	u16 options;
	u32 base;
	int z;

	if (get_omap_rev() >= OMAP_4460_ES1_DOT_0)
		base = PUBLIC_API_BASE_4460;
	else
		base = PUBLIC_API_BASE_4430;

	rom_get_mem_driver = API(base + PUBLIC_GET_DRIVER_MEM_OFFSET);
	z = rom_get_mem_driver(&io, device);
	if (z)
		return -1;

	md = &local_md_device;
	memset(md, 0, sizeof(struct mem_device));
	options = 0; // 1 = init phoenix pmic?
	md->initialized   = 0;
	md->device_type   = device;
	md->xip_device    = 0;
	md->search_size   = 0;
	md->base_address  = 0;
	md->hs_toc_mask   = 0;
	md->gp_toc_mask   = 0;
	md->boot_options  = &options;
	md->device_data   = (void*) 0x80000000;
	memset(md->device_data, 0, 2500);

	z = io->init(md);
	if (z)
		return -1;

	rd.sector_start = start;
	rd.sector_count = count;
	rd.destination = data;
	z = io->read(md, &rd);

	return 0;
}
Example #22
0
void HelpDialog::checkUpdates()
{
	if (networkManager->networkAccessible()==QNetworkAccessManager::Accessible)
	{
		if (updateState==HelpDialog::Updating)
		{
			qWarning() << "Already checking updates...";
			return;
		}

		QUrl API("https://api.github.com/repos/Stellarium/stellarium/releases/latest");
		connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadComplete(QNetworkReply*)));
		QNetworkRequest request;
		request.setUrl(API);
		request.setRawHeader("User-Agent", StelUtils::getUserAgentString().toUtf8());
		#if QT_VERSION >= 0x050600
		request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
		#endif
		downloadReply = networkManager->get(request);

		updateState = HelpDialog::Updating;
	}
}
Example #23
0
bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length UNUSED, uint8_t* public_key, size_t* public_key_length)
{
    struct tr_dh_ctx* handle = raw_handle;
    word32 my_private_key_length;
    word32 my_public_key_length;
    tr_lock* rng_lock = get_rng_lock();

    TR_ASSERT(handle != NULL);
    TR_ASSERT(public_key != NULL);

    if (handle->private_key == NULL)
    {
        handle->private_key = tr_malloc(handle->key_length);
    }

    tr_lockLock(rng_lock);

    if (!check_result(API(DhGenerateKeyPair)(&handle->dh, get_rng(), handle->private_key, &my_private_key_length, public_key,
        &my_public_key_length)))
    {
        tr_lockUnlock(rng_lock);
        return false;
    }

    tr_lockUnlock(rng_lock);

    tr_dh_align_key(public_key, my_public_key_length, handle->key_length);

    handle->private_key_length = my_private_key_length;

    if (public_key_length != NULL)
    {
        *public_key_length = handle->key_length;
    }

    return true;
}
Example #24
0
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_key, size_t other_public_key_length)
{
    struct tr_dh_ctx* handle = raw_handle;
    struct tr_dh_secret* ret;
    word32 my_secret_key_length;

    TR_ASSERT(handle != NULL);
    TR_ASSERT(other_public_key != NULL);

    ret = tr_dh_secret_new(handle->key_length);

    if (check_result(API(DhAgree)(&handle->dh, ret->key, &my_secret_key_length, handle->private_key, handle->private_key_length,
        other_public_key, other_public_key_length)))
    {
        tr_dh_secret_align(ret, my_secret_key_length);
    }
    else
    {
        tr_dh_secret_free(ret);
        ret = NULL;
    }

    return ret;
}
Example #25
0
static void
on_junk (GObject *gobject, GParamSpec *pspec, gpointer user_data)
{
	(void)user_data;
	g_print("junk happened!: %s: %s\n", pspec->name, api_get_junk(API(gobject)));
}
Example #26
0
Filtro::Filtro() {
    aAPI = API();
}
Example #27
0
                fail("unknown symbol %S", part);
            value += sym->value;
        }
    }
    return value;
}

#define API(n)                          { L#n, do_##n }
struct api
{
    const wchar_t *name;
    int (*fn)(int argc, wchar_t **argv);
};
struct api apitab[] =
{
    API(CreateFile),
    API(DeleteFile),
    API(CreateDirectory),
    API(RemoveDirectory),
    API(GetFileInformation),
    API(SetFileAttributes),
    API(SetFileTime),
    API(SetEndOfFile),
    API(FindFiles),
    API(FindStreams),
    API(MoveFileEx),
    API(RenameStream),
};
static int apicmp(const void *p1, const void *p2)
{
    const struct api *api1 = (const struct api *)p1;
Example #28
0
char * nvram_get(char * section, char * key)
{
    API();
    return _nvram_buf_get(section, key);
}
Example #29
0
int32_t nvram_commit(char flash)
{
    int32_t rc = OK;
    int32_t sect = 0, i = 0;
    FILE * fp = NULL;
    char * buffer, * p, * q;

    API();

    fp = fopen(NVRAM_CACHE_FILE, "r+");
    if(!fp)
    {
        DEBUG("failed to open %s, %s.\n", NVRAM_CACHE_FILE, __FUNCTION__);
        rc = NG;
        goto __quit;
    }

    buffer = (char *)malloc(nvram_mtd_size);
    if(!buffer)
    {
        DEBUG("failed to alloc buffer (%d) for nvram! %s.\n", nvram_mtd_size, __FUNCTION__);
        rc = NG;
        goto __quit;
    }

    for (sect=0; sect<sectionnum; sect++)
    {
        p = buffer + nvramcache[sect].offset + 4; /* reserve 4 bytes for crc32 */
        if(strcmp(nvramcache[sect].name,"uboot") != 0)
        {
            *p = '\0';
            p++;
        }
        q = p + nvramcache[sect].size;
        for (i=0; i<MAX_ENTRY; i++)
        {
            if (nvramcache[sect].cache[i].name)
            {
                int32_t l;
                ASSERT(nvramcache[sect].cache[i].value);
                l = strlen(nvramcache[sect].cache[i].name)
                  + strlen(nvramcache[sect].cache[i].value) + 2;
                if (p+l>=q)
                {
                    DEBUG("exceed nvram section size %u!\n", nvramcache[sect].size);
                    rc = NG;
                    goto __quit;
                }
                sprintf(p, "%s=%s",
                    nvramcache[sect].cache[i].name,
                    nvramcache[sect].cache[i].value);
                p += l;
            }
        }
        *p = '\0'; // just make sure
        
        if(strcmp(nvramcache[sect].name,"uboot") == 0)
            nvramcache[sect].crc =
                crc32(0, (uint8_t *)(buffer + nvramcache[sect].offset+4), nvramcache[sect].size-4);
        else
            nvramcache[sect].crc =
                crc32(0, (uint8_t *)(buffer + nvramcache[sect].offset+5), nvramcache[sect].size-5);

        *(uint32_t *)(buffer + nvramcache[sect].offset) = nvramcache[sect].crc;
        DEBUG("cal crc32 = 0x%8x!\n", nvramcache[sect].crc);
        p = buffer + nvramcache[sect].offset;

        fseek(fp, nvramcache[sect].offset, SEEK_SET);
        DEBUG("write nvram raw data, offset %u, size %u!\n",
            nvramcache[sect].offset, nvramcache[sect].size);
        i = fwrite(buffer + nvramcache[sect].offset, 1, nvramcache[sect].size, fp);
        ASSERT(i == nvramcache[sect].size);
    }

    if (flash)
    {
        i = flash_write(buffer, 0, nvram_mtd_size);
        ASSERT(i>0);
    }


__quit:
    sfree(buffer);
    fclose(fp);
    return rc;
}
Example #30
0
int32_t nvram_parse(char * section, char * cachefile)
{
    int32_t rc = 0;
    FILE * fp = NULL;
    size_t len = 0;
    char * data, * p, * q;
    int32_t i = 0, j = 0;

    API();

    fp = fopen(cachefile, "r+b");
    if (!fp)
    {
        DEBUG("failed to load %s, %s, %s\n", cachefile, strerror(errno), __FUNCTION__);
        return NG;
    }

    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    data = (char *)malloc(len);
    if(!data)
    {
        DEBUG("failed to alloc buffer (%zu) for nvram! %s.\n", len, __FUNCTION__);
        fclose(fp);
        return NG;
    }
    memset(data, 0, len);
    rc = fread(data, 1, len, fp);
    DEBUG("rc %d, len %zu\n", rc, len);
    ASSERT(rc == len);

    nvramcache = (section_t *)malloc(sizeof(section_t)*sectionnum);
    memset(nvramcache, 0, sizeof(sizeof(section_t)*sectionnum));
    for (i = 0; i<sectionnum; i++)
    {
        uint32_t secrc = 0;
        nvramcache[i].name = nvlayout[i].name;
        nvramcache[i].flag = nvlayout[i].flag;
        nvramcache[i].size = nvlayout[i].size;
        nvramcache[i].offset = nvlayout[i].offset;
        j = 0;
        p = data+nvramcache[i].offset;
        secrc = *(uint32_t *)p;
        if(strcmp(nvramcache[i].name,"uboot") == 0)
            nvramcache[i].crc =
                crc32(0, (uint8_t *)(data + nvramcache[i].offset+4), nvramcache[i].size-4);
        else
            nvramcache[i].crc =
                crc32(0, (uint8_t *)(data + nvramcache[i].offset+5), nvramcache[i].size-5);            

        // DEBUG("file crc: %x, cal crc: %x\n", secrc, nvramcache[i].crc);

        if (secrc == 0 || secrc != nvramcache[i].crc)
        {
            DEBUG("data error in section %s.\n", nvramcache[i].name);
            continue;
        }

        if(strcmp(nvramcache[i].name,"uboot") == 0)
            p = p + 4;
        else
            p = p + 4 + 1;

        /* parsing the content, k=v\0k1=v1\0......kx=vx */
        while (p < data+nvramcache[i].offset+nvramcache[i].size+1 && j < MAX_ENTRY)
        {
            if (*p == 0) break;
            q = strchr(p, '=');
            if (!q)
            {
                DEBUG("nvram format error!\n");
                break;
            }
            *q = 0;
            q++;
            // DEBUG("\t<%s>=<%s>\n", p, q);
            nvramcache[i].cache[j].name = strdup(p);
            nvramcache[i].cache[j].value = strdup(q);
            p = q + strlen(q) + 1;
            j++;
        }
    }

    fclose(fp);
    return OK;
}