本文整理汇总了C++中BN_bn2dec函数的典型用法代码示例。如果您正苦于以下问题:C++ BN_bn2dec函数的具体用法?C++ BN_bn2dec怎么用?C++ BN_bn2dec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BN_bn2dec函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:ei-grad,项目名称:rsazkp,代码行数:31,代码来源:server.c
示例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;
}
开发者ID:roguehit,项目名称:aos2,代码行数:32,代码来源:server.c
示例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;
}
开发者ID:AzerTyQsdF,项目名称:osx,代码行数:30,代码来源:ssl_util_ssl.c
示例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;
}
开发者ID:jeremyschlatter,项目名称:cpp-driver,代码行数:33,代码来源:test_utils.hpp
示例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;
}
开发者ID:greenplum-db,项目名称:libusual,代码行数:29,代码来源:tls_cert.c
示例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);
}
}
开发者ID:weltonvaz,项目名称:Primos,代码行数:30,代码来源:fatorialBig.c
示例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;
}
开发者ID:DocPsy,项目名称:MacRuby,代码行数:29,代码来源:ossl_asn1.c
示例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;
}
开发者ID:pexip,项目名称:os-apache2,代码行数:29,代码来源:ssl_util_ssl.c
示例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;
}
开发者ID:Talos-crypto,项目名称:Talos-Android,代码行数:8,代码来源:paillier.c
示例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);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:10,代码来源:bcode.c
示例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);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:10,代码来源:bcode.c
示例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);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:14,代码来源:factor.c
示例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;
}
开发者ID:AlexeyBychkov,项目名称:robovm,代码行数:11,代码来源:java_math_NativeBN.cpp
示例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');
}
开发者ID:Hooman3,项目名称:minix,代码行数:66,代码来源:factor.c
示例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;
}
开发者ID:Ar3kkusu,项目名称:android_libcore,代码行数:16,代码来源:BNInterface.c
示例16: ASN1_INTEGER_to_BN
QString a1int::toDec() const
{
QString r;
if (in->length == 0) {
return r;
}
BIGNUM *bn = ASN1_INTEGER_to_BN(in, NULL);
char *res = BN_bn2dec(bn);
r = res;
BN_free(bn);
OPENSSL_free(res);
return r;
}
开发者ID:LiTianjue,项目名称:xca,代码行数:13,代码来源:asn1int.cpp
示例17: handle_serial
static char *
handle_serial (char * serial)
{
int hex = NULL != strchr (serial, ':');
/* Convert serial to a decimal serial when input is
a hexidecimal representation of the serial */
if (hex)
{
unsigned int i,ii;
char *tmp_serial = (char*) calloc (strlen (serial) + 1,1);
for (i=0,ii=0; '\0'!=serial[i];i++)
{
if (':'!=serial[i])
tmp_serial[ii++]=serial[i];
}
serial=tmp_serial;
}
else
{
unsigned int i;
for (i=0; ! hex && '\0' != serial[i]; i++)
hex = 'a'==serial[i]||'b'==serial[i]||'c'==serial[i]||'d'==serial[i]||'e'==serial[i]||'f'==serial[i];
}
if (hex)
{
ASN1_INTEGER* ai;
BIGNUM *ret;
BIO* in = BIO_new_mem_buf(serial, -1);
char buf[1025];
ai=ASN1_INTEGER_new();
if (ai == NULL) return NULL;
if (!a2i_ASN1_INTEGER(in,ai,buf,1024))
{
return NULL;
}
ret=ASN1_INTEGER_to_BN(ai,NULL);
if (ret == NULL)
{
return NULL;
}
else
{
serial = BN_bn2dec(ret);
}
}
return serial;
} /* handle_serial */
开发者ID:flomar,项目名称:sscep,代码行数:51,代码来源:sscep.c
示例18: x509_get_serial
char *
x509_get_serial (x509_cert_t *cert)
{
ASN1_INTEGER *asn1_i;
BIGNUM *bignum;
char *serial;
asn1_i = X509_get_serialNumber(cert);
bignum = ASN1_INTEGER_to_BN(asn1_i, NULL);
serial = BN_bn2dec(bignum);
BN_free(bignum);
return serial;
}
开发者ID:alshalan,项目名称:Mobile-OpenVPN,代码行数:14,代码来源:ssl_verify_openssl.c
示例19: main
int
main()
{
BIGNUM two, three, four, five;
BIGNUM answer;
BN_CTX *context;
size_t length;
char *string;
context = BN_CTX_new();
if (context == NULL)
fail("BN_CTX_new");
/* answer = 5 ** 4 ** 3 ** 2 */
BN_init(&two);
BN_init(&three);
BN_init(&four);
BN_init(&five);
if (BN_set_word(&two, 2) == 0 ||
BN_set_word(&three, 3) == 0 ||
BN_set_word(&four, 4) == 0 ||
BN_set_word(&five, 5) == 0)
fail("BN_set_word");
BN_init(&answer);
if (BN_exp(&answer, &three, &two, context) == 0 ||
BN_exp(&answer, &four, &answer, context) == 0 ||
BN_exp(&answer, &five, &answer, context) == 0)
fail("BN_exp");
/* string = decimal answer */
string = BN_bn2dec(&answer);
if (string == NULL)
fail("BN_bn2dec");
length = strlen(string);
printf(" First 20 digits: %.20s\n", string);
if (length >= 20)
printf(" Last 20 digits: %.20s\n", string + length - 20);
printf("Number of digits: %zd\n", length);
OPENSSL_free(string);
BN_free(&answer);
BN_free(&five);
BN_free(&four);
BN_free(&three);
BN_free(&two);
BN_CTX_free(context);
return 0;
}
开发者ID:Anatolt,项目名称:RosettaCodeData,代码行数:50,代码来源:arbitrary-precision-integers--included--2.c
示例20: serverReadKey
int serverReadKey(Server * server, char * key) {
FILE * f;
if ((f = fopen(key, "r")) == NULL) {
fprintf(stderr, "Can't open file %s!\n", key);
return 1;
}
server->rsa = RSA_new();
if (server->rsa == NULL)
return 1;
if(PEM_read_RSA_PUBKEY(f, &server->rsa, (pem_password_cb *) password_callback, NULL) == 0) {
ERR_print_errors_fp(stderr);
return 1;
}
char * tmpstr;
tmpstr = BN_bn2dec(server->rsa->n);
printf("Модуль: %s\n", tmpstr);
OPENSSL_free(tmpstr);
tmpstr = BN_bn2dec(server->rsa->e);
printf("Публичная экспонента: %s\n", tmpstr);
OPENSSL_free(tmpstr);
printf("&p = %x\n", server->rsa->p);
if (server->rsa->p){
tmpstr = BN_bn2dec(server->rsa->p);
printf("p = %s\n", tmpstr);
OPENSSL_free(tmpstr);
}
return 0;
}
开发者ID:ei-grad,项目名称:rsazkp,代码行数:37,代码来源:server.c
注:本文中的BN_bn2dec函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论