本文整理汇总了C++中BN_bn2dec函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_bn2dec函数的具体用法?C++ BN_bn2dec怎么用?C++ BN_bn2dec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BN_bn2dec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serverAct1
int serverAct1(Server * server) {
int bytes;
char buf[1024];
char * bufptr = buf;
char * tmpstr;
printf("\n==== Этап 1 ====\n\n");
server->k = BN_new();
server->m = BN_new();
bytes = BIO_read(server->conn, buf, 1024);
buf[bytes] = 0;
BN_dec2bn(&server->k, buf);
tmpstr = BN_bn2dec(server->k);
printf("k = %s\n", tmpstr);
OPENSSL_free(tmpstr);
BIO_puts(server->conn, "OK");
bytes = BIO_read(server->conn, buf, 1024);
buf[bytes] = 0;
BN_dec2bn(&server->m, buf);
tmpstr = BN_bn2dec(server->m);
printf("m = %s\n", tmpstr);
OPENSSL_free(tmpstr);
BIO_puts(server->conn, "OK");
return 0;
}
示例2: compute_mod
/*--------------------------------------------------*/
void compute_mod(Task * task)
{
BN_CTX *context;
BIGNUM *r,*a,*p,*m;
if(task->p==NULL){
fprintf(stderr,"Wrong Exponent\n");
exit(0);
}
/*Just printing out the client send numbers*/
printf("Printing the Exponent\n");
print_bignumber(task->p);
printf("Printing the Prime\n");
print_bignumber(task->m);
context = BN_CTX_new();
r = BN_new();
a = BN_new();
p = BN_new();
m = BN_new();
BN_dec2bn(&a,"2");
BN_dec2bn(&p,task->p);
BN_dec2bn(&m,task->m);
BN_mod_exp(r,a,p,m,context);
printf("Response ----\n");
strcpy(task->response,BN_bn2dec(r));
print_bignumber(task->response);
return;
}
示例3: SSL_X509_getBC
/* retrieve basic constraints ingredients */
BOOL SSL_X509_getBC(X509 *cert, int *ca, int *pathlen)
{
X509_EXTENSION *ext;
BASIC_CONSTRAINTS *bc;
int idx;
BIGNUM *bn = NULL;
char *cp;
if ((idx = X509_get_ext_by_NID(cert, NID_basic_constraints, -1)) < 0)
return FALSE;
ext = X509_get_ext(cert, idx);
if (ext == NULL)
return FALSE;
if ((bc = (BASIC_CONSTRAINTS *)X509V3_EXT_d2i(ext)) == NULL)
return FALSE;
*ca = bc->ca;
*pathlen = -1 /* unlimited */;
if (bc->pathlen != NULL) {
if ((bn = ASN1_INTEGER_to_BN(bc->pathlen, NULL)) == NULL)
return FALSE;
if ((cp = BN_bn2dec(bn)) == NULL)
return FALSE;
*pathlen = atoi(cp);
OPENSSL_free(cp);
BN_free(bn);
}
BASIC_CONSTRAINTS_free(bc);
return TRUE;
}
示例4: decode_varint
/**
* Decode a two's complement varint (e.g. Java BigInteger) byte array into its
* numerical value
*
* @param byte_array Two's complement varint byte array
* @return Numerical value of the varint
*/
static std::string decode_varint(const char *byte_array) {
std::string result;
// Assuming positive numbers only
//TODO: Add check for bit to return negative values
BIGNUM *value = BN_bin2bn(reinterpret_cast<unsigned const char *>(byte_array), static_cast<int>(strlen(byte_array)), NULL);
if (value) {
char* decimal = BN_bn2dec(value);
result = std::string(decimal);
OPENSSL_free(decimal);
//Normalize - strip leading zeros
for (unsigned int n = 0; n < result.size(); ++n) {
if (result.at(n) == '0') {
result.replace(n, 1, "");
} else {
break;
}
}
if (result.size() == 0) {
result = "0";
}
}
BN_free(value);
return result;
}
示例5: tls_parse_bigint
/* Convert ASN1_INTEGER to decimal string string */
static int
tls_parse_bigint(struct tls *ctx, const ASN1_INTEGER *asn1int, const char **dst_p)
{
long small;
BIGNUM *big;
char *tmp, buf[64];
*dst_p = NULL;
small = ASN1_INTEGER_get(asn1int);
if (small < 0) {
big = ASN1_INTEGER_to_BN(asn1int, NULL);
if (big) {
tmp = BN_bn2dec(big);
if (tmp)
*dst_p = strdup(tmp);
OPENSSL_free(tmp);
}
BN_free(big);
} else {
snprintf(buf, sizeof buf, "%lu", small);
*dst_p = strdup(buf);
}
if (*dst_p)
return 0;
tls_set_errorx(ctx, "cannot parse serial");
return -1;
}
示例6: main
int main(int argc, char *argv[])
{
BIGNUM *fat; // declaração de uma variável Big
BN_ULONG a, f; // apenas um long int normal
char *resp;
int i;
/* Primeiro tem que alocar as variáveis BIGNUM */
fat = BN_new();
for (i = 1; i < argc; i++) {
printf("Calculando fatorial de %s\n", argv[i]);
/* convertendo string em long int */
f = atoll(argv[i]);
/* forma de atribuir 1 a uma variável BIGNUM */
BN_dec2bn(&fat, "1");
for (a = 2; a <= f; a++) {
BN_mul_word(fat, a);
}
/* gerando uma string imprimível do resultado */
resp = BN_bn2dec(fat);
/* impressão do resultado (agora é uma string) */
printf("Fatorial de %s = %s\n", argv[i], resp);
}
}
示例7: asn1integer_to_num
VALUE
asn1integer_to_num(ASN1_INTEGER *ai)
{
BIGNUM *bn;
#if DO_IT_VIA_RUBY
char *txt;
#endif
VALUE num;
if (!ai) {
ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
}
if (!(bn = ASN1_INTEGER_to_BN(ai, NULL))) {
ossl_raise(eOSSLError, NULL);
}
#if DO_IT_VIA_RUBY
if (!(txt = BN_bn2dec(bn))) {
BN_free(bn);
ossl_raise(eOSSLError, NULL);
}
num = rb_cstr_to_inum(txt, 10, Qtrue);
OPENSSL_free(txt);
#else
num = ossl_bn_new(bn);
#endif
BN_free(bn);
return num;
}
示例8: modssl_X509_getBC
/* retrieve basic constraints ingredients */
BOOL modssl_X509_getBC(X509 *cert, int *ca, int *pathlen)
{
BASIC_CONSTRAINTS *bc;
BIGNUM *bn = NULL;
char *cp;
bc = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
if (bc == NULL)
return FALSE;
*ca = bc->ca;
*pathlen = -1 /* unlimited */;
if (bc->pathlen != NULL) {
if ((bn = ASN1_INTEGER_to_BN(bc->pathlen, NULL)) == NULL) {
BASIC_CONSTRAINTS_free(bc);
return FALSE;
}
if ((cp = BN_bn2dec(bn)) == NULL) {
BN_free(bn);
BASIC_CONSTRAINTS_free(bc);
return FALSE;
}
*pathlen = atoi(cp);
OPENSSL_free(cp);
BN_free(bn);
}
BASIC_CONSTRAINTS_free(bc);
return TRUE;
}
示例9: BN_to_jstring
jstring* BN_to_jstring(JNIEnv *env, BIGNUM *num) {
char *numString;
jstring res;
numString = BN_bn2dec(num);
res = (*env)->NewStringUTF(env, numString);
free(numString);
return res;
}
示例10: pn
void
pn(const char *str, const struct number *n)
{
char *p = BN_bn2dec(n->number);
if (p == NULL)
err(1, "BN_bn2dec failed");
(void)fputs(str, stderr);
(void)fprintf(stderr, " %s (%u)\n" , p, n->scale);
OPENSSL_free(p);
}
示例11: pbn
void
pbn(const char *str, const BIGNUM *n)
{
char *p = BN_bn2dec(n);
if (p == NULL)
err(1, "BN_bn2dec failed");
(void)fputs(str, stderr);
(void)fprintf(stderr, " %s\n", p);
OPENSSL_free(p);
}
示例12: BN_print_dec_fp
/*
* Sigh.. No _decimal_ output to file functions in BN.
*/
static void
BN_print_dec_fp(FILE *fp, const BIGNUM *num)
{
char *buf;
buf = BN_bn2dec(num);
if (buf == NULL)
return; /* XXX do anything here? */
fprintf(fp, buf);
free(buf);
}
示例13: Java_java_math_NativeBN_BN_1bn2dec
extern "C" jstring Java_java_math_NativeBN_BN_1bn2dec(JNIEnv* env, jclass, jlong a) {
if (!oneValidHandle(env, a)) return NULL;
char* tmpStr = BN_bn2dec(toBigNum(a));
if (tmpStr == NULL) {
return NULL;
}
char* retStr = leadingZerosTrimmed(tmpStr);
jstring returnJString = env->NewStringUTF(retStr);
OPENSSL_free(tmpStr);
return returnJString;
}
示例14: pr_fact
/*
* pr_fact - print the factors of a number
*
* If the number is 0 or 1, then print the number and return.
* If the number is < 0, print -1, negate the number and continue
* processing.
*
* Print the factors of the number, from the lowest to the highest.
* A factor will be printed numtiple times if it divides the value
* multiple times.
*
* Factors are printed with leading tabs.
*/
static void
pr_fact(BIGNUM *val)
{
const ubig *fact; /* The factor found. */
/* Firewall - catch 0 and 1. */
if (BN_is_zero(val) || BN_is_one(val))
errx(1, "numbers <= 1 aren't permitted.");
/* Factor value. */
BN_print_dec_fp(stdout, val);
putchar(':');
for (fact = &prime[0]; !BN_is_one(val); ++fact) {
/* Look for the smallest factor. */
while (fact <= pr_limit) {
if (BN_mod_word(val, (BN_ULONG)*fact) == 0)
break;
fact++;
}
/* Watch for primes larger than the table. */
if (fact > pr_limit) {
#ifdef HAVE_OPENSSL
BIGNUM *bnfact;
bnfact = BN_new();
BN_set_word(bnfact, (BN_ULONG)*(fact - 1));
BN_sqr(bnfact, bnfact, ctx);
if (BN_cmp(bnfact, val) > 0
|| BN_is_prime(val, PRIME_CHECKS, NULL, NULL,
NULL) == 1) {
putchar(' ');
BN_print_dec_fp(stdout, val);
} else
pollard_rho(val);
#else
printf(" %s", BN_bn2dec(val));
#endif
break;
}
/* Divide factor out until none are left. */
do {
printf(" %lu", *fact);
BN_div_word(val, (BN_ULONG)*fact);
} while (BN_mod_word(val, (BN_ULONG)*fact) == 0);
/* Let the user know we're doing something. */
fflush(stdout);
}
putchar('\n');
}
示例15: NativeBN_BN_bn2dec
/**
* public static native java.lang.String BN_bn2dec(int)
*/
static jstring NativeBN_BN_bn2dec(JNIEnv* env, jclass cls, BIGNUM* a) {
if (!oneValidHandle(env, a)) return NULL;
char* tmpStr;
char* retStr;
tmpStr = BN_bn2dec(a);
if (tmpStr != NULL) {
retStr = leadingZerosTrimmed(tmpStr);
jstring returnJString = ((*env)->NewStringUTF(env, (mcSignednessBull)retStr));
OPENSSL_free(tmpStr);
return returnJString;
}
else return NULL;
}