• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ BN_is_negative函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ASN1_bn_print

int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
                  unsigned char *ign, int indent)
{
    int n, rv = 0;
    const char *neg;
    unsigned char *buf = NULL, *tmp = NULL;
    int buflen;

    if (num == NULL)
        return 1;
    neg = BN_is_negative(num) ? "-" : "";
    if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT))
        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)bn_get_words(num)[0], neg,
                       (unsigned long)bn_get_words(num)[0]) <= 0)
            return 0;
        return 1;
    }

    buflen = BN_num_bytes(num) + 1;
    buf = tmp = OPENSSL_malloc(buflen);
    if (buf == NULL)
        goto err;
    buf[0] = 0;
    if (BIO_printf(bp, "%s%s\n", number,
                   (neg[0] == '-') ? " (Negative)" : "") <= 0)
        goto err;
    n = BN_bn2bin(num, buf + 1);

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

    if (ASN1_buf_print(bp, tmp, n, indent + 4) == 0)
        goto err;
    rv = 1;
err:
    OPENSSL_clear_free(buf, buflen);
    return rv;
}
开发者ID:mtrojnar,项目名称:openssl,代码行数:49,代码来源:t_pkey.c


示例17: is_legal

/* g^x is a legal value */
static int is_legal(const BIGNUM *gx, const JPAKE_CTX *ctx)
    {
    BIGNUM *t;
    int res;
    
    if(BN_is_negative(gx) || BN_is_zero(gx) || BN_cmp(gx, ctx->p.p) >= 0)
	return 0;

    t = BN_new();
    BN_mod_exp(t, gx, ctx->p.q, ctx->p.p, ctx->ctx);
    res = BN_is_one(t);
    BN_free(t);

    return res;
    }
开发者ID:qzhouayi,项目名称:New_graduation_thesis,代码行数:16,代码来源:zhjpake.c


示例18: set_Jprojective_coordinate_GFp

static int set_Jprojective_coordinate_GFp(const EC_GROUP *group, BIGNUM *out,
                                          const BIGNUM *in, BN_CTX *ctx) {
  if (in == NULL) {
    return 1;
  }
  if (BN_is_negative(in) ||
      BN_cmp(in, &group->field) >= 0) {
    OPENSSL_PUT_ERROR(EC, EC_R_COORDINATES_OUT_OF_RANGE);
    return 0;
  }
  if (group->meth->field_encode) {
    return group->meth->field_encode(group, out, in, ctx);
  }
  return BN_copy(out, in) != NULL;
}
开发者ID:AadityaDev,项目名称:AadityaDev.github.io,代码行数:15,代码来源:simple.c


示例19: check_mod_inverse

static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
                             const BIGNUM *m, int check_reduced, BN_CTX *ctx) {
  BN_CTX_start(ctx);
  BIGNUM *tmp = BN_CTX_get(ctx);
  int ret = tmp != NULL &&
            bn_mul_consttime(tmp, a, ainv, ctx) &&
            bn_div_consttime(NULL, tmp, tmp, m, ctx);
  if (ret) {
    *out_ok = BN_is_one(tmp);
    if (check_reduced && (BN_is_negative(ainv) || BN_cmp(ainv, m) >= 0)) {
      *out_ok = 0;
    }
  }
  BN_CTX_end(ctx);
  return ret;
}
开发者ID:0x64616E69656C,项目名称:boringssl,代码行数:16,代码来源:rsa.c


示例20: bsqrt

static void
bsqrt(void)
{
	struct number	*n;
	struct number	*r;
	BIGNUM		*x, *y;
	u_int		scale, onecount;
	BN_CTX		*ctx;

	onecount = 0;
	n = pop_number();
	if (n == NULL) {
		return;
	}
	if (BN_is_zero(n->number)) {
		r = new_number();
		push_number(r);
	} else if (BN_is_negative(n->number))
		warnx("square root of negative number");
	else {
		scale = max(bmachine.scale, n->scale);
		normalize(n, 2*scale);
		x = BN_dup(n->number);
		bn_checkp(x);
		bn_check(BN_rshift(x, x, BN_num_bits(x)/2));
		y = BN_new();
		bn_checkp(y);
		ctx = BN_CTX_new();
		bn_checkp(ctx);
		for (;;) {
			bn_checkp(BN_copy(y, x));
			bn_check(BN_div(x, NULL, n->number, x, ctx));
			bn_check(BN_add(x, x, y));
			bn_check(BN_rshift1(x, x));
			if (bsqrt_stop(x, y, &onecount))
				break;
		}
		r = bmalloc(sizeof(*r));
		r->scale = scale;
		r->number = y;
		BN_free(x);
		BN_CTX_free(ctx);
		push_number(r);
	}

	free_number(n);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:47,代码来源:bcode.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BN_is_odd函数代码示例发布时间:2022-05-30
下一篇:
C++ BN_is_bit_set函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap