Ejemplo n.º 1
0
void pki_crl::fromData(const unsigned char *p, db_header_t *head)
{
	int size;

	size = head->len - sizeof(db_header_t);

	QByteArray ba((const char*)p, size);
	d2i(ba);

	if (ba.count() > 0) {
		my_error(tr("Wrong Size %1").arg(ba.count()));
	}
}
Ejemplo n.º 2
0
static int parse_int(const char *buf, int i, int len, int *val_return)
{
	int val, d;

	if (i >= len)
		return -1;

	val = d2i(buf[i]);
	if (val < 0)
		return -1;
	else
		i++;

	while (i < len) {
		d = d2i(buf[i]);
		if (d < 0)
			break;
		val = val * 10 + d;
		i++;
	}
	*val_return = val;
	return i;
}
Ejemplo n.º 3
0
Archivo: bigint.cpp Proyecto: foo/ii
// Moves carry foreward.
// This function is more general then fix_under_0 because
// fix_over_9 is used in addition as well as in multiplication,
// where temporarily excessive values can range up to 9*9 = 81
// with carry = 8
void fix_over_9(digit* big)
{
  while(big)
  {
    if(d2i(big->n) > 9)
    {
      int carry = d2i(big->n) / 10;
      big->n = i2d(d2i(big->n) % 10);

      assert(carry > 0);

      if(big->next)
	big->next->n = i2d(d2i(big->next->n) + carry);
      else
      {
	big->next = new digit;
	big->next->next = 0;
	big->next->n = i2d(carry);
      }
    }
      
    big = big->next;
  }
}
Ejemplo n.º 4
0
void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x)
	{
	BUF_MEM *b = NULL;
	const unsigned char *p;
	void *ret=NULL;
	int len;

	len = asn1_d2i_read_bio(in, &b);
	if(len < 0) goto err;

	p=(unsigned char *)b->data;
	ret=d2i(x,&p,len);
err:
	if (b != NULL) BUF_MEM_free(b);
	return(ret);
	}
Ejemplo n.º 5
0
void pki_x509req::fromData(const unsigned char *p, db_header_t *head )
{
	int size;

	size = head->len - sizeof(db_header_t);

	QByteArray ba((const char *)p, size);
	privkey = NULL;

	d2i(ba);
	pki_openssl_error();

	if (ba.count() > 0) {
		my_error(tr("Wrong Size %1").arg(ba.count()));
	}
}
Ejemplo n.º 6
0
char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
	     pem_password_cb *cb, void *u)
	{
	unsigned char *p=NULL,*data=NULL;
	long len;
	char *ret=NULL;

	if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
		return NULL;
	p = data;
	ret=d2i(x,&p,len);
	if (ret == NULL)
		PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
	OPENSSL_free(data);
	return(ret);
	}
Ejemplo n.º 7
0
void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
			pem_password_cb *cb, void *u)
	{
	const unsigned char *p=NULL;
	unsigned char *data=NULL;
	long len;
	char *ret=NULL;

	if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
		return NULL;
	p = data;
	ret=d2i(x,&p,len);
	if (ret == NULL)
		OPENSSL_PUT_ERROR(PEM, ERR_R_ASN1_LIB);
	OPENSSL_free(data);
	return ret;
	}
Ejemplo n.º 8
0
Archivo: bigint.cpp Proyecto: foo/ii
// Printing bignum using additional O(n) memory.
void printbigint(const digit* big)
{
  std::vector<char> digits;
  while(big)
  {
    digits.push_back(big->n);
    big = big->next;
  }
  if(digits.empty())
    std::cout << '0' << '\n';
  else
  {
    for(std::vector<char>::reverse_iterator i = digits.rbegin(); i != digits.rend(); ++i)
    {
      std::cout << d2i(*i);
    }
    std::cout << '\n';
  }
}
Ejemplo n.º 9
0
char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
	{
	unsigned char *b,*p;
	long i;
	char *ret;

	if (x == NULL) return(NULL);

	i=(long)i2d(x,NULL);
	b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
	if (b == NULL)
		{ ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
	p= b;
	i=i2d(x,&p);
	p= b;
	ret=d2i(NULL,&p,i);
	OPENSSL_free(b);
	return(ret);
	}
Ejemplo n.º 10
0
/*
 * Convert bytea to X.
 */
void * pgx_X_from_bytea(const bytea *raw,
		void * *(new_object)(void),
		int (*d2i)(BIO *, void **)) {
    BIO *bio;
	void *x;
	int r;

    bio = BIO_new_mem_buf(VARDATA(raw), VARSIZE(raw) - VARHDRSZ);
    BIO_set_close(bio, BIO_NOCLOSE);
	x = new_object();

    if ((r = d2i(bio, &x)) == NULL) {
        ereport(ERROR,
                (errcode(ERRCODE_DATA_CORRUPTED), errmsg("%s:%d: unable to retrieve data (%d) 2", __FILE__, __LINE__, ERR_get_error())));
    }

    BIO_free(bio);

    return x;
}
Ejemplo n.º 11
0
void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
	{
	unsigned char *b,*p;
	const unsigned char *p2;
	int i;
	char *ret;

	if (x == NULL) return(NULL);

	i=i2d(x,NULL);
	b=(unsigned char *) OPENSSL_malloc(i+10);
	if (b == NULL)
		{ ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
	p= b;
	i=i2d(x,&p);
	p2= b;
	ret=(char*) d2i(NULL,&p2,i);
	OPENSSL_free(b);
	return(ret);
	}
Ejemplo n.º 12
0
void pki_evp::fromData(const unsigned char *p, db_header_t *head )
{
	int version, type, size;

	size = head->len - sizeof(db_header_t);
	version = head->version;

	QByteArray ba((const char*)p, size);

	if (key)
		EVP_PKEY_free(key);

	key = NULL;
	type = db::intFromData(ba);
	ownPass = db::intFromData(ba);
	if (version < 2) {
		d2i_old(ba, type);
	} else {
		d2i(ba);
	}
	pki_openssl_error();

	encKey = ba;
}
Ejemplo n.º 13
0
int gen_twiddle_fft32x32(int *w, int n, double scale)
{
    int i, j, k, s=0, t;
    const double PI = 3.141592654;
    for (j = 1, k = 0; j < n >> 2; j = j << 2, s++) {
        for (i = t=0; i < n >> 2; i += j, t++) {
            w[k +  5] = d2i(scale * cos(6.0 * PI * i / n));
            w[k +  4] = d2i(scale * sin(6.0 * PI * i / n));

            w[k +  3] = d2i(scale * cos(4.0 * PI * i / n));
            w[k +  2] = d2i(scale * sin(4.0 * PI * i / n));

            w[k +  1] = d2i(scale * cos(2.0 * PI * i / n));
            w[k +  0] = d2i(scale * sin(2.0 * PI * i / n));

            k += 6;
        }
    }
    return k;
}
Ejemplo n.º 14
0
KJS::Object KstBindDataVector::construct(KJS::ExecState *exec, const KJS::List& args) {
  KstRVectorPtr v;

  KstDataSourcePtr dp = extractDataSource(exec, args[0]);
  // Constructor: DataVector(DataSource, field)
  if (args.size() == 2) {
    if (args[1].type() != KJS::StringType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Object();
    }

    QString field = args[1].toString(exec).qstring();

    v = new KstRVector(dp, field, QString::null, 0, -1, -1, false, false);
    KST::addVectorToList(KstVectorPtr(v));
  }

  // Constructor: DataVector(DataSource, field, start, n)
  if (args.size() == 4) {
    if (args[1].type() != KJS::StringType ||
        args[2].type() != KJS::NumberType ||
        args[3].type() != KJS::NumberType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Object();
    }

    QString field = args[1].toString(exec).qstring();
    int start = d2i(args[2].toNumber(exec));
    int count = d2i(args[3].toNumber(exec));

    v = new KstRVector(dp, field, QString::null, start, count, -1, false, false);
    KST::addVectorToList(KstVectorPtr(v));
  }

  // Constructor: DataVector(DataSource, field, start, n, skip)
  if (args.size() == 5) {
    if (args[1].type() != KJS::StringType ||
        args[2].type() != KJS::NumberType ||
        args[3].type() != KJS::NumberType ||
        args[4].type() != KJS::NumberType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Object();
    }

    QString field = args[1].toString(exec).qstring();
    int start = d2i(args[2].toNumber(exec));
    int count = d2i(args[3].toNumber(exec));
    int skip = d2i(args[4].toNumber(exec));

    v = new KstRVector(dp, field, QString::null, start, count, skip, true, false);
    KST::addVectorToList(KstVectorPtr(v));
  }


  // Constructor: DataVector(DataSource, field, start, n, skip, ave)
  if (args.size() == 6) {
    if (args[1].type() != KJS::StringType ||
        args[2].type() != KJS::NumberType ||
        args[3].type() != KJS::NumberType ||
        args[4].type() != KJS::NumberType ||
        args[5].type() != KJS::BooleanType) {
      KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
      exec->setException(eobj);
      return KJS::Object();
    }

    QString field = args[1].toString(exec).qstring();
    int start = d2i(args[2].toNumber(exec));
    int count = d2i(args[3].toNumber(exec));
    int skip = d2i(args[4].toNumber(exec));
    bool ave = d2i(args[5].toBoolean(exec));

    v = new KstRVector(dp, field, QString::null, start, count, skip, true, ave);
    KST::addVectorToList(KstVectorPtr(v));
  }

  if (!v) {
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
    exec->setException(eobj);
    return KJS::Object();
  }

  return KJS::Object(new KstBindDataVector(exec, v));
}
Ejemplo n.º 15
0
static int test_certs(BIO *fp)
{
    int count;
    char *name = 0;
    char *header = 0;
    unsigned char *data = 0;
    long len;
    typedef X509 *(*d2i_X509_t)(X509 **, const unsigned char **, long);
    typedef int (*i2d_X509_t)(X509 *, unsigned char **);
    int err = 0;

    for (count = 0;
         !err && PEM_read_bio(fp, &name, &header, &data, &len);
	 ++count) {
        int trusted = strcmp(name, PEM_STRING_X509_TRUSTED) == 0;
        d2i_X509_t d2i = trusted ? d2i_X509_AUX : d2i_X509;
        i2d_X509_t i2d = trusted ? i2d_X509_AUX : i2d_X509;
        X509 *cert = NULL;
	const unsigned char *p = data;
        unsigned char *buf = NULL;
        unsigned char *bufp;
        long enclen;

	if (!trusted
            && strcmp(name, PEM_STRING_X509) != 0
	    && strcmp(name, PEM_STRING_X509_OLD) != 0) {
	    fprintf(stderr, "unexpected PEM object: %s\n", name);
            err = 1;
	    goto next;
        }
        cert = d2i(NULL, &p, len);

        if (cert == NULL || (p - data) != len) {
	    fprintf(stderr, "error parsing input %s\n", name);
            err = 1;
            goto next;
        }

        /* Test traditional 2-pass encoding into caller allocated buffer */
        enclen = i2d(cert, NULL);
        if (len != enclen) {
	    fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
                    enclen, name, len);
            err = 1;
            goto next;
        }
        if ((buf = bufp = OPENSSL_malloc(len)) == NULL) {
            perror("malloc");
            err = 1;
            goto next;
        }
        enclen = i2d(cert, &bufp);
        if (len != enclen) {
	    fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
                    enclen, name, len);
            err = 1;
            goto next;
        }
        enclen = (long) (bufp - buf);
        if (enclen != len) {
	    fprintf(stderr, "unexpected buffer position after encoding %s\n",
                    name);
            err = 1;
            goto next;
        }
        if (memcmp(buf, data, len) != 0) {
	    fprintf(stderr, "encoded content of %s does not match input\n",
                    name);
            err = 1;
            goto next;
        }
        OPENSSL_free(buf);
        buf = NULL;

        /* Test 1-pass encoding into library allocated buffer */
        enclen = i2d(cert, &buf);
        if (len != enclen) {
	    fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
                    enclen, name, len);
            err = 1;
            goto next;
        }
        if (memcmp(buf, data, len) != 0) {
	    fprintf(stderr, "encoded content of %s does not match input\n",
                    name);
            err = 1;
            goto next;
        }

        if (trusted) {
            /* Encode just the cert and compare with initial encoding */
            OPENSSL_free(buf);
            buf = NULL;

            /* Test 1-pass encoding into library allocated buffer */
            enclen = i2d(cert, &buf);
            if (enclen > len) {
                fprintf(stderr, "encoded length %ld of %s > input length %ld\n",
                        enclen, name, len);
                err = 1;
                goto next;
            }
            if (memcmp(buf, data, enclen) != 0) {
                fprintf(stderr, "encoded cert content does not match input\n");
                err = 1;
                goto next;
            }
        }

	/*
	 * If any of these were null, PEM_read() would have failed.
	 */
    next:
        X509_free(cert);
        OPENSSL_free(buf);
	OPENSSL_free(name);
	OPENSSL_free(header);
	OPENSSL_free(data);
    }

    if (ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) {
        /* Reached end of PEM file */
        if (count > 0) {
            ERR_clear_error();
            return 1;
        }
    }

    /* Some other PEM read error */
    print_errors();
    return 0;
}
Ejemplo n.º 16
0
void build_graph(int* F, int F_num, int V_num, double* curv, double* center_dist, double* border, double* graph, int* graph_size, int switcher)
{
	//double center_basis = 10.0;
	//double* center_bias = (double*) mxMalloc(2*sizeof(double));
	//center_bias[0] = 15.2/*16*/;center_bias[1] = 23.0;
	double bias = -2.0;
	double* center_coef = (double*) mxMalloc(V_num*sizeof(double));

	switch (switcher)
	{
		case 1:
			for (int i = 0;i < V_num;i++)
			{
				if (center_dist[i] > border[i]-bias)
				{
					center_coef[i] = 10000;
				}
				else
				{
					center_coef[i] = 1;//pow((border[i] - center_dist[i]) / border[i], 4);
				}
			}
			break;
		case 2:
			for (int i = 0;i < V_num;i++)
			{
				if (center_dist[i] < border[i])
				{
					center_coef[i] = 100;
				}
				else
				{
					center_coef[i] = 1;//pow((center_dist[i] - border) / border, 0.5);
				}
			}		
			break;
		case 3:
			for (int i = 0;i < V_num;i++)
			{
				center_coef[i] = 1;
			}
			break;
		case 4:
			for (int i = 0;i < V_num;i++)
			{
				center_coef[i] = 1;
			}
			for (int i = 0;i < d2i(border[0]);i++)
			{
				center_coef[d2i(center_dist[i])-1] = 9999;
			}
			break;
		default: break;
	}

	for (int i = 0;i < F_num;i++)
	{
		int* temp = getV(F,i);
		//mexPrintf("%d\n",i);
		build_each(*temp, *(temp+1), center_coef, curv, graph, graph_size, switcher);
		build_each(*(temp+1), *temp, center_coef, curv, graph, graph_size, switcher);
		build_each(*temp, *(temp+2), center_coef, curv, graph, graph_size, switcher);
		build_each(*(temp+2), *temp, center_coef, curv, graph, graph_size, switcher);
		build_each(*(temp+1), *(temp+2), center_coef, curv, graph, graph_size, switcher);
		build_each(*(temp+2), *(temp+1), center_coef, curv, graph, graph_size, switcher);
	}
}
Ejemplo n.º 17
0
STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,
		    d2i_of_void *d2i, void (*free_func)(void *), int ex_tag,
		    int ex_class)
	{
	ASN1_const_CTX c;
	STACK *ret=NULL;

	if ((a == NULL) || ((*a) == NULL))
		{
		if ((ret=sk_new_null()) == NULL)
			{
			ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE);
			goto err;
			}
		}
	else
		ret=(*a);

	c.p= *pp;
	c.max=(length == 0)?0:(c.p+length);

	c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,(long)(c.max-c.p));
	if (c.inf & 0x80) goto err;
	if (ex_class != c.xclass)
		{
		ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);
		goto err;
		}
	if (ex_tag != c.tag)
		{
		ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);
		goto err;
		}
	if ((c.slen+c.p) > c.max)
		{
		ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);
		goto err;
		}
	/* check for infinite constructed - it can be as long
	 * as the amount of data passed to us */
	if (c.inf == (V_ASN1_CONSTRUCTED+1))
		c.slen=(long)(length+ *pp-c.p);
	c.max=c.p+c.slen;

	while (c.p < c.max)
		{
		char *s;

		if (M_ASN1_D2I_end_sequence()) break;
		/* XXX: This was called with 4 arguments, incorrectly, it seems
		   if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) */
		if ((s=d2i(NULL,&c.p,c.slen)) == NULL)
			{
			ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
			asn1_add_error(*pp,(int)(c.q- *pp));
			goto err;
			}
		if (!sk_push(ret,s)) goto err;
		}
	if (a != NULL) (*a)=ret;
	*pp=c.p;
	return(ret);
err:
	if ((ret != NULL) && ((a == NULL) || (*a != ret)))
		{
		if (free_func != NULL)
			sk_pop_free(ret,free_func);
		else
			sk_free(ret);
		}
	return(NULL);
	}
Ejemplo n.º 18
0
int parse_time(const char *buf, int offset, int len, time_t * time_return)
{
	struct tm tm;
	time_t t;
	int i = offset;

	i = skip_word(buf, i, len);
	if (i < 0)
		return -1;
	i = skip_separator(buf, i, len);
	if (i < 0)
		return -1;

	if (i >= len)
		return -1;

	if (d2i(buf[i]) >= 0) {
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937)
			return -1;

		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = skip_word(buf, i, len);
		if (i < 0)
			return -1;
	} else {		
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937 || tm.tm_year > 2040)
			return -1;
	}

	if (tm.tm_year < 2038) {
		tm.tm_year -= 1900;
		tm.tm_isdst = -1;
		t = mktime_gmt(&tm);
		if (t == -1)
			return -1;
	} else {
		t = time_t_max;
	}

	*time_return = t;
	return i;
}
QSize KstPlotLabel::size() const {
  return QSize(d2i(_textWidth*_cosr + _textHeight*_sinr), d2i(_textHeight*_cosr + _textWidth*_sinr));
}