本文整理匯總了C++中BN_dec2bn函數的典型用法代碼示例。如果您正苦於以下問題:C++ BN_dec2bn函數的具體用法?C++ BN_dec2bn怎麽用?C++ BN_dec2bn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BN_dec2bn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: fill_GOST94_params
/*
* Fill GOST 94 params, searching them in R3410_paramset array
* by nid of paramset
*
*/
int fill_GOST94_params (DSA * dsa, int nid)
{
R3410_params *params = R3410_paramset;
while (params->nid != NID_undef && params->nid != nid)
params++;
if (params->nid == NID_undef)
{
GOSTerr (GOST_F_FILL_GOST94_PARAMS, GOST_R_UNSUPPORTED_PARAMETER_SET);
return 0;
}
#define dump_signature(a,b,c)
if (dsa->p)
{
BN_free (dsa->p);
}
dsa->p = NULL;
BN_dec2bn (&(dsa->p), params->p);
if (dsa->q)
{
BN_free (dsa->q);
}
dsa->q = NULL;
BN_dec2bn (&(dsa->q), params->q);
if (dsa->g)
{
BN_free (dsa->g);
}
dsa->g = NULL;
BN_dec2bn (&(dsa->g), params->a);
return 1;
}
示例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: 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;
}
示例4: main
int
main(int argc, char *argv[])
{
BIGNUM *val;
int ch;
char *p, buf[LINE_MAX]; /* > max number of digits. */
ctx = BN_CTX_new();
val = BN_new();
if (val == NULL)
errx(1, "can't initialise bignum");
while ((ch = getopt(argc, argv, "h")) != -1)
switch (ch) {
case 'h':
hflag++;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
/* No args supplied, read numbers from stdin. */
if (argc == 0)
for (;;) {
if (fgets(buf, sizeof(buf), stdin) == NULL) {
if (ferror(stdin))
err(1, "stdin");
exit (0);
}
for (p = buf; isblank(*p); ++p);
if (*p == '\n' || *p == '\0')
continue;
if (*p == '-')
errx(1, "negative numbers aren't permitted.");
if (BN_dec2bn(&val, buf) == 0 &&
BN_hex2bn(&val, buf) == 0)
errx(1, "%s: illegal numeric format.", buf);
pr_fact(val);
}
/* Factor the arguments. */
else
for (; *argv != NULL; ++argv) {
if (argv[0][0] == '-')
errx(1, "negative numbers aren't permitted.");
if (BN_dec2bn(&val, argv[0]) == 0 &&
BN_hex2bn(&val, argv[0]) == 0)
errx(1, "%s: illegal numeric format.", argv[0]);
pr_fact(val);
}
exit(0);
}
示例5: priv_to_pub
int priv_to_pub (unsigned char * const result, const size_t m, const unsigned char * const priv, const size_t n) {
int ret = 0;
int i = 0;
BIGNUM * privbn = 0;
BN_dec2bn(&privbn,"0");
BIGNUM * pow256 = 0;
BN_dec2bn(&pow256,"1");
BIGNUM * one256 = 0;
BN_dec2bn(&one256,"256");
const unsigned char * input_it = priv + n - 1;
for (i=0; i<n; i++) {
BIGNUM * input_bn = 0;
char * input_str = malloc(4);
sprintf(input_str,"%d",*input_it);
BN_dec2bn(&input_bn,input_str);
BN_CTX * ctx = BN_CTX_new();
BN_mul(input_bn, pow256, input_bn, ctx);
BN_add(privbn,privbn,input_bn);
BN_mul(pow256, pow256, one256, ctx);
BN_free(input_bn);
if (input_str != 0) {
free(input_str);
}
BN_CTX_free(ctx);
input_it--;
}
EC_GROUP * group = EC_GROUP_new_by_curve_name(NID_secp256k1);
EC_POINT * pub_key = EC_POINT_new(group);
BN_CTX * ctx = BN_CTX_new();
EC_POINT_mul(group, pub_key, privbn, 0, 0, ctx);
if (m == 65) {
EC_POINT_point2oct(group,pub_key,POINT_CONVERSION_UNCOMPRESSED,result,m,ctx);
}
else {
EC_POINT_point2oct(group,pub_key,POINT_CONVERSION_COMPRESSED,result,m,ctx);
}
EC_GROUP_free(group);
EC_POINT_free(pub_key);
BN_CTX_free(ctx);
BN_free(privbn);
BN_free(pow256);
BN_free(one256);
return(0);
}
示例6: serverAct2
int serverAct2(Server * server) {
int bytes;
char buf[1024];
printf("\n==== Этап 2 ====\n\n");
bytes = BIO_read(server->conn, buf, 1024);
buf[bytes] = 0;
printf("Получен шифртекст: %s\n", buf);
server->C = BN_new();
if (!BN_dec2bn(&server->C, buf)) {
fprintf(stderr, "Ошибка при получении шифртекста!");
BIO_puts(server->conn, "ERR");
return 1;
}
BIO_puts(server->conn, "OK");
printf("Шифртест принят.\n");
return 0;
}
示例7: dec2bin
static int
dec2bin(uint8_t *out, const char *in)
{
int ret, l;
char *tmp = NULL;
BIGNUM *B;
if ((NULL == (B = BN_new())) ||
(0 == BN_dec2bn(&B, in)) ||
(NULL == (tmp = BN_bn2hex(B)))) {
ret = RFC6287_ERR_OPENSSL;
goto err;
}
if (256 < (l = strlen(tmp))) {
ret = RFC6287_INVALID_CHALLENGE;
goto err;
}
if (1 < l && '0' == tmp[0])
ret = hex2bin(out, tmp + 1);
else
ret = hex2bin(out, tmp);
err:
if (NULL != tmp)
OPENSSL_free(tmp);
if (NULL != B)
BN_free(B);
return ret;
}
示例8: 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);
}
}
示例9: ribs_ssl_set_options
int ribs_ssl_set_options(SSL_CTX *ssl_ctx, char *cipher_list) {
/* bugs */
SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); /* almost all bugs */
SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2); /* disable SSLv2 per RFC 6176 */
SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv3); /* disable SSLv3. goodbye IE6 */
SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_COMPRESSION);
SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
/* ciphers */
if (!cipher_list)
cipher_list = _HTTP_SERVER_SSL_CIPHERS;
SSL_CTX_set_options(ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
if (0 == SSL_CTX_set_cipher_list(ssl_ctx, cipher_list))
return LOGGER_ERROR("failed to initialize SSL:cipher_list"), -1;
/* DH 2048 bits */
SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
DH *dh = DH_new();
dh->p = get_rfc3526_prime_2048(NULL);
BN_dec2bn(&dh->g, "2");
if (0 == SSL_CTX_set_tmp_dh(ssl_ctx, dh))
return LOGGER_ERROR("failed to initialize SSL:dh"), -1;
DH_free(dh);
/* Ecliptic Curve DH */
SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
EC_KEY *ecdh = EC_KEY_new_by_curve_name(OBJ_sn2nid("prime256v1"));
if (ecdh == NULL)
return LOGGER_ERROR("failed to initialize SSL:edch"), -1;
SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh);
EC_KEY_free(ecdh);
return 0;
}
示例10: serverAct3
int serverAct3(Server * server) {
int bytes;
char buf[1024];
printf("\n==== Этап 3 ====\n\n");
bytes = BIO_read(server->conn, buf, 1024);
buf[bytes] = 0;
printf("Получен X: %s\n", buf);
server->X = BN_new();
if (!BN_dec2bn(&server->X, buf)) {
fprintf(stderr, "Ошибка при получении X!");
BIO_puts(server->conn, "ERR");
return 1;
}
BIO_puts(server->conn, "OK");
printf("X принят.\n");
return 0;
}
示例11: BN_new
BIGNUM *BN_get(lua_State *L, int i)
{
BIGNUM *x = BN_new();
switch (lua_type(L, i))
{
case LUA_TNUMBER:
BN_set_word(x, lua_tointeger(L, i));
break;
case LUA_TSTRING:
{
const char *s = lua_tostring(L, i);
if (s[0] == 'X' || s[0] == 'x') BN_hex2bn(&x, s + 1);
else BN_dec2bn(&x, s);
break;
}
case LUA_TUSERDATA:
BN_copy(x, CHECK_OBJECT(i, BIGNUM, "openssl.bn"));
break;
case LUA_TNIL:
BN_free(x);
x = NULL;
break;
}
return x;
}
示例12: fbytes
static int fbytes(unsigned char *buf, int num)
{
int ret = 0;
BIGNUM *tmp = NULL;
if (use_fake == 0)
return old_rand->bytes(buf, num);
use_fake = 0;
if (fbytes_counter >= 8)
return 0;
if (!TEST_ptr(tmp = BN_new()))
return 0;
if (!TEST_true(BN_dec2bn(&tmp, numbers[fbytes_counter]))) {
BN_free(tmp);
return 0;
}
fbytes_counter++;
if (TEST_int_eq(BN_num_bytes(tmp), num)
&& TEST_true(BN_bn2bin(tmp, buf)))
ret = 1;
BN_free(tmp);
return ret;
}
示例13: APSetKey
Boolean APSetKey(CFStringRef key)
{
hash = CFSTR("");
blacklist = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
// Create a new key
rsaKey = RSA_new();
// Public exponent is always 3
BN_hex2bn(&rsaKey->e, "3");
CFMutableStringRef mutableKey = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, key);
if (!mutableKey)
return FALSE;
CFIndex maximumCStringLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(mutableKey), kCFStringEncodingMacRoman) + 1;
char *keyCStringBuffer = malloc(maximumCStringLength);
// Determine if we have a hex or decimal key
CFStringLowercase(mutableKey, NULL);
if (CFStringHasPrefix(mutableKey, CFSTR("0x"))) {
CFStringTrim(mutableKey, CFSTR("0x"));
CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
BN_hex2bn(&rsaKey->n, keyCStringBuffer);
}
else {
CFStringGetCString(mutableKey, keyCStringBuffer, maximumCStringLength, kCFStringEncodingMacRoman);
BN_dec2bn(&rsaKey->n, keyCStringBuffer);
}
CFRelease(mutableKey);
free(keyCStringBuffer);
return TRUE;
}
示例14: performDH
struct sec performDH(char *pubkeyRec,DH *privkey){
struct sec s;
int secret_size;
/* Send the public key to the peer.
* How this occurs will be specific to your situation (see main text below) */
/* Receive the public key from the peer. In this example we're just hard coding a value */
BIGNUM *pubkey = NULL;
if(0 == (BN_dec2bn(&pubkey, pubkeyRec))) handleErrors();
/* Compute the shared secret */
unsigned char *secret;
if(NULL == (secret = OPENSSL_malloc(sizeof(unsigned char) * (DH_size(privkey))))) handleErrors();
if(0 > (secret_size = DH_compute_key(secret, pubkey, privkey))) handleErrors();
/* Do something with the shared secret */
/* Note secret_size may be less than DH_size(privkey) */
printf("The shared secret is:\n");
strcpy(s.value,secret);
s.length=secret_size;
/* Clean up */
OPENSSL_free(secret);
BN_free(pubkey);
DH_free(privkey);
return s;
}
示例15: fbytes
int fbytes(unsigned char *buf, int num)
{
int ret;
BIGNUM *tmp = NULL;
if (use_fake == 0)
return old_rand->bytes(buf, num);
use_fake = 0;
if (fbytes_counter >= 8)
return 0;
tmp = BN_new();
if (!tmp)
return 0;
if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) {
BN_free(tmp);
return 0;
}
fbytes_counter++;
if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf))
ret = 0;
else
ret = 1;
BN_free(tmp);
return ret;
}