当前位置: 首页>>代码示例>>C++>>正文


C++ BN_is_negative函数代码示例

本文整理汇总了C++中BN_is_negative函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_is_negative函数的具体用法?C++ BN_is_negative怎么用?C++ BN_is_negative使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了BN_is_negative函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ec_GF2m_simple_mul

/* Computes the sum
 *     scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1]
 * gracefully ignoring NULL scalar values.
 */
int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
	{
	BN_CTX *new_ctx = NULL;
	int ret = 0;
	size_t i;
	EC_POINT *p=NULL;
	EC_POINT *acc = NULL;

	if (ctx == NULL)
		{
		ctx = new_ctx = BN_CTX_new();
		if (ctx == NULL)
			return 0;
		}

	/* This implementation is more efficient than the wNAF implementation for 2
	 * or fewer points.  Use the ec_wNAF_mul implementation for 3 or more points,
	 * or if we can perform a fast multiplication based on precomputation.
	 */
	if ((scalar && (num > 1)) || (num > 2) || (num == 0 && EC_GROUP_have_precompute_mult(group)))
		{
		ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
		goto err;
		}

	if ((p = EC_POINT_new(group)) == NULL) goto err;
	if ((acc = EC_POINT_new(group)) == NULL) goto err;

	if (!EC_POINT_set_to_infinity(group, acc)) goto err;

	if (scalar)
		{
		if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err;
		if (BN_is_negative(scalar))
			if (!group->meth->invert(group, p, ctx)) goto err;
		if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
		}

	for (i = 0; i < num; i++)
		{
		if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err;
		if (BN_is_negative(scalars[i]))
			if (!group->meth->invert(group, p, ctx)) goto err;
		if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
		}

	if (!EC_POINT_copy(r, acc)) goto err;

	ret = 1;

  err:
	if (p) EC_POINT_free(p);
	if (acc) EC_POINT_free(acc);
	if (new_ctx != NULL)
		BN_CTX_free(new_ctx);
	return ret;
	}
开发者ID:Chenhx,项目名称:moai-dev,代码行数:62,代码来源:ec2_mult.c

示例2: OPENSSL_PUT_ERROR

ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
    ASN1_ENUMERATED *ret;
    int len,j;

    if (ai == NULL)
        ret=M_ASN1_ENUMERATED_new();
    else
        ret=ai;
    if (ret == NULL)
    {
        OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ASN1_R_NESTED_ASN1_ERROR);
        goto err;
    }
    if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
    else ret->type=V_ASN1_ENUMERATED;
    j=BN_num_bits(bn);
    len=((j == 0)?0:((j/8)+1));
    if (ret->length < len+4)
    {
        unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
        if (!new_data)
        {
            OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        ret->data=new_data;
    }

    ret->length=BN_bn2bin(bn,ret->data);
    return(ret);
err:
    if (ret != ai) M_ASN1_ENUMERATED_free(ret);
    return(NULL);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:35,代码来源:a_enum.c

示例3: store_array

static void
store_array(void)
{
	struct number *inumber;
	struct value *value;
	struct stack *stack;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		value = pop();
		if (value == NULL) {
			free_number(inumber);
			return;
		}
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number)) {
			warnx("negative idx");
			stack_free_value(value);
		} else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX) {
			warnx("idx too big");
			stack_free_value(value);
		} else {
			stack = &bmachine.reg[reg];
			frame_assign(stack, idx, value);
		}
		free_number(inumber);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:33,代码来源:bcode.c

示例4: encode_varint

  /**
   * Encode the varint using two's complement
   *
   * @return Vector of bytes in two's complement
   */
  std::vector<unsigned char> encode_varint() const {
    // Handle NULL and zero varint
    if (!big_number_ || BN_num_bytes(big_number_.get()) == 0) {
      std::vector<unsigned char> bytes(1);
      bytes[0] = 0x00;
      return bytes;
    }

    size_t number_of_bytes = BN_num_bytes(big_number_.get()) + 1;
    std::vector<unsigned char> bytes(number_of_bytes);
    if (BN_bn2bin(big_number_.get(), &bytes[1]) > 0) {
      // Set the sign and convert to two's complement (if necessary)
      if (BN_is_negative(big_number_.get())) {
        bool is_carry = true;
        for (ssize_t i = number_of_bytes - 1; i >= 0; --i) {
          bytes[i] ^= 0xFF;
          if (is_carry) {
            is_carry = ((++bytes[i]) == 0);
          }
        }
        bytes[0] |= 0x80;
      } else {
        bytes[0] = 0x00;
      }
    }

    return bytes;
  }
开发者ID:hpcc-systems,项目名称:cpp-driver,代码行数:33,代码来源:bignumber.hpp

示例5: BN_bn2cbb

int BN_bn2cbb(CBB *cbb, const BIGNUM *bn) {
  /* Negative numbers are unsupported. */
  if (BN_is_negative(bn)) {
    OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
    return 0;
  }

  CBB child;
  if (!CBB_add_asn1(cbb, &child, CBS_ASN1_INTEGER)) {
    OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
    return 0;
  }

  /* The number must be padded with a leading zero if the high bit would
   * otherwise be set (or |bn| is zero). */
  if (BN_num_bits(bn) % 8 == 0 &&
      !CBB_add_u8(&child, 0x00)) {
    OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
    return 0;
  }

  uint8_t *out;
  if (!CBB_add_space(&child, &out, BN_num_bytes(bn))) {
    OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
    return 0;
  }
  BN_bn2bin(bn, out);
  if (!CBB_flush(cbb)) {
    OPENSSL_PUT_ERROR(BN, BN_R_ENCODE_ERROR);
    return 0;
  }
  return 1;
}
开发者ID:reaperhulk,项目名称:ring,代码行数:33,代码来源:bn_asn1.c

示例6: load_array

static void
load_array(void)
{
	struct number *inumber, *n;
	struct stack *stack;
	struct value *v;
	struct value copy;
	u_long idx;
	int reg;

	reg = readreg();
	if (reg >= 0) {
		inumber = pop_number();
		if (inumber == NULL)
			return;
		idx = get_ulong(inumber);
		if (BN_is_negative(inumber->number))
			warnx("negative idx");
		else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX)
			warnx("idx too big");
		else {
			stack = &bmachine.reg[reg];
			v = frame_retrieve(stack, idx);
			if (v == NULL || v->type == BCODE_NONE) {
				n = new_number();
				bn_check(BN_zero(n->number));
				push_number(n);
			}
			else
				push(stack_dup_value(v, &copy));
		}
		free_number(inumber);
	}
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:34,代码来源:bcode.c

示例7: bn8_from_bn

void bn8_from_bn(bn8 r, const BIGNUM *a)
{
	int n = BN_num_bytes(a);
	memset(r, 0, BN8_SIZE);
	BN_bn2bin(a, r+1+(BN8_SIZE-1)-n);
	if(BN_is_negative(a))
		bn8_negative(r);
}
开发者ID:12019,项目名称:bitcoin-smartcard,代码行数:8,代码来源:bn8_misc.c

示例8: FC_ASSERT

 int64_t bigint::to_int64() const
 {
   FC_ASSERT(BN_num_bits(n) <= 63);
   size_t size = BN_num_bytes(n);
   uint64_t abs_value = 0;
   BN_bn2bin(n, (unsigned char*)&abs_value + (sizeof(uint64_t) - size));
   return BN_is_negative(n) ? -(int64_t)bswap_64(abs_value) : bswap_64(abs_value);
 }
开发者ID:FollowMyVote,项目名称:fc,代码行数:8,代码来源:bigint.cpp

示例9: rsa_greater_than_pow2

int rsa_greater_than_pow2(const BIGNUM *b, int n) {
  if (BN_is_negative(b) || n == INT_MAX) {
    return 0;
  }

  int b_bits = BN_num_bits(b);
  return b_bits > n + 1 || (b_bits == n + 1 && !BN_is_pow2(b));
}
开发者ID:freeors,项目名称:Rose,代码行数:8,代码来源:rsa_impl.c

示例10: Java_java_math_NativeBN_sign

extern "C" int Java_java_math_NativeBN_sign(JNIEnv* env, jclass, jlong a) {
  if (!oneValidHandle(env, a)) return -2;
  if (BN_is_zero(toBigNum(a))) {
      return 0;
  } else if (BN_is_negative(toBigNum(a))) {
    return -1;
  }
  return 1;
}
开发者ID:AlexeyBychkov,项目名称:robovm,代码行数:9,代码来源:java_math_NativeBN.cpp

示例11: _hc_BN_to_integer

int
_hc_BN_to_integer(BIGNUM *bn, heim_integer *integer)
{
    integer->length = BN_num_bytes(bn);
    integer->data = malloc(integer->length);
    if (integer->data == NULL)
	return ENOMEM;
    BN_bn2bin(bn, integer->data);
    integer->negative = BN_is_negative(bn);
    return 0;
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:11,代码来源:common.c

示例12: BN_to_integer

static krb5_error_code
BN_to_integer(krb5_context context, BIGNUM *bn, heim_integer *integer)
{
    integer->length = BN_num_bytes(bn);
    integer->data = malloc(integer->length);
    if (integer->data == NULL) {
	krb5_clear_error_message(context);
	return ENOMEM;
    }
    BN_bn2bin(bn, integer->data);
    integer->negative = BN_is_negative(bn);
    return 0;
}
开发者ID:heimdal,项目名称:heimdal,代码行数:13,代码来源:pkinit.c

示例13: bn2heim_int

static int
bn2heim_int(BIGNUM *bn, heim_integer *integer)
{
    integer->length = BN_num_bytes(bn);
    integer->data = malloc(integer->length);
    if (integer->data == NULL) {
	integer->length = 0;
	return ENOMEM;
    }
    BN_bn2bin(bn, integer->data);
    integer->negative = BN_is_negative(bn);
    return 0;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:13,代码来源:rsa.c

示例14: bignum_to_bytea

/**
 * Convert BIGNUM to bytea. (Copied from pg-bignum)
 */
bytea * bignum_to_bytea(BIGNUM *bn) {
    int len;
    bytea *results;

    // create bytea results.
    len = BN_num_bytes(bn);
    results = (bytea *) palloc(len + 1 + VARHDRSZ);
    *VARDATA(results) = BN_is_negative(bn) ? 0x01 : 0x00;
    BN_bn2bin(bn, (unsigned char *) VARDATA(results) + 1);
    SET_VARSIZE(results, len + 1 + VARHDRSZ);

    return results;
}
开发者ID:beargiles,项目名称:pg-cert,代码行数:16,代码来源:pgx_cert_utils.c

示例15: ASN1_bn_print

int
ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
    unsigned char *buf, int off)
{
	int n, i;
	const char *neg;

	if (num == NULL)
		return (1);
	neg = (BN_is_negative(num)) ? "-" : "";
	if (!BIO_indent(bp, off, 128))
		return 0;
	if (BN_is_zero(num)) {
		if (BIO_printf(bp, "%s 0\n", number) <= 0)
			return 0;
		return 1;
	}

	if (BN_num_bytes(num) <= BN_BYTES) {
		if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg,
		    (unsigned long)num->d[0], neg,
		    (unsigned long)num->d[0]) <= 0)
			return (0);
	} else {
		buf[0] = 0;
		if (BIO_printf(bp, "%s%s", number,
		    (neg[0] == '-') ? " (Negative)" : "") <= 0)
			return (0);
		n = BN_bn2bin(num, &buf[1]);

		if (buf[1] & 0x80)
			n++;
		else
			buf++;

		for (i = 0; i < n; i++) {
			if ((i % 15) == 0) {
				if (BIO_puts(bp, "\n") <= 0 ||
				    !BIO_indent(bp, off + 4, 128))
					return 0;
			}
			if (BIO_printf(bp, "%02x%s", buf[i],
			    ((i + 1) == n) ? "" : ":") <= 0)
				return (0);
		}
		if (BIO_write(bp, "\n", 1) <= 0)
			return (0);
	}
	return (1);
}
开发者ID:2trill2spill,项目名称:nextgen,代码行数:50,代码来源:t_pkey.c


注:本文中的BN_is_negative函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。