Openssl BIGNUM BN_mod() [英] Openssl BIGNUM BN_mod()

查看:610
本文介绍了Openssl BIGNUM BN_mod()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误输出141 mod 8 ??

我只是试图从文件读取输入然后应用mod

与8.Can你请解释我在哪里我错了?



我尝试过:



< pre lang =c ++> #include < < span class =code-leadattribute> stdio.h >
#include < openssl / bn.h >

BIGNUM * read_f( const char * filename)
{
FILE * fp;
char text [ 700 ];
fp = fopen(filename, r);
fgets(text, 700 ,fp);
// fclose(fp);
// char * point = text;
BIGNUM * a = BN_new();
BN_hex2bn(& a,( const char *)text);
fclose(fp);
返回 a;
}
void main(){
const char * filename = input / tA.txt ;
BIGNUM * p = BN_new();
p = read_f(filename);
BN_print_fp(stdout,p);
printf( \ n);
BIGNUM * tmp = BN_new();
BIGNUM * val = BN_new();
BN_set_word(val, 8 );

// BIGNUM * v = BN_new();
// BN_set_word(v,1);
BN_CTX * ctx = BN_CTX_new();
// 计算mod值
BN_mod(tmp,p,val,ctx );
BN_print_fp(stdout,tmp);
printf( \ n);
// calculati
/ / BN_mod_mul(tmp,p,v,val,ctx);
// BN_print_fp(stdout,tmp);
// printf(\ n);
}

解决方案

它工作正常,当然,试试:

  #include   <   openssl / bn.h  >  
int main()
{
BIGNUM * b1 = BN_new();
BIGNUM * b2 = BN_new();
BIGNUM * b3 = BN_new();
BN_set_word(b1, 141 );
BN_set_word(b2, 8 );
BN_CTX * ctx = BN_CTX_new();

BN_mod(b3,b1,b2,ctx);
BN_print_fp(stdout,b3);

BN_free(b1);
BN_free(b2);
BN_free(b3);
BN_CTX_free(ctx);

return 0 ;
}


Wrong output for 141 mod 8 ??
I am just trying to read an input from file and then apply mod
with 8.Can u please explain me where I am getting wrong ?

What I have tried:

#include<stdio.h>
#include<openssl/bn.h>

BIGNUM * read_f(const char *filename)
{
    FILE *fp;
    char text[700];
    fp=fopen(filename,"r");
    fgets(text,700,fp);
    //fclose(fp);
    //char *point=text;
    BIGNUM*a =BN_new();
    BN_hex2bn(&a, (const char *) text);
    fclose(fp);
    return a;
}
void main(){
 const char *filename="input/tA.txt";
    BIGNUM *p=  BN_new();
    p=read_f(filename);
    BN_print_fp(stdout,p);
    printf("\n");
	BIGNUM *tmp=BN_new();
	BIGNUM *val=BN_new();
	BN_set_word(val,8);
      
	//BIGNUM *v=BN_new();
	//BN_set_word(v,1);
 	BN_CTX *ctx=BN_CTX_new();
        //calculating mod value
  	BN_mod(tmp,p,val,ctx);	
	BN_print_fp(stdout,tmp);
	printf("\n");
 	//calculati
 	// BN_mod_mul(tmp,p,v,val,ctx);
	//BN_print_fp(stdout,tmp);
	//printf("\n");
}

解决方案

It works fine, of course, try:

#include <openssl/bn.h>
int main()
{
  BIGNUM *b1=BN_new();
  BIGNUM *b2=BN_new();
  BIGNUM *b3=BN_new();
  BN_set_word(b1,141);
  BN_set_word(b2,8);
  BN_CTX *ctx=BN_CTX_new();

  BN_mod(b3,b1,b2,ctx);
  BN_print_fp(stdout,b3);

  BN_free(b1);
  BN_free(b2);
  BN_free(b3);
  BN_CTX_free(ctx);

  return 0;
}


这篇关于Openssl BIGNUM BN_mod()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆