不知道算不算bug哎

1 view
Skip to first unread message

yaoshi lee

unread,
Nov 11, 2009, 3:56:18 AM11/11/09
to sh...@googlegroups.com
#include<stdio.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
int main (void)
{
char *key="1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef7" ;
BIGNUM *a = BN_new ();
BIGNUM *p = BN_new ();
BIGNUM *m = BN_new ();
BIGNUM *r = BN_new ();
BN_CTX *ctx = BN_CTX_new ();
BN_hex2bn (&m, key);
printf("strlen key is %d\n",strlen(key));
BN_hex2bn (&p, "512");
BN_hex2bn (&a, "2");
BN_mod_exp(r,a,p,m,ctx);
char *q = BN_bn2hex (r);
if (q)
{
printf ("%s\n", q);
printf("strlen of mod is %d\n",strlen(q));
OPENSSL_free (q);
}
BN_CTX_free(ctx);
}

Jianshi Huang

unread,
Nov 11, 2009, 6:37:44 AM11/11/09
to sh...@googlegroups.com
没问题,就是前头多了个 0 罢了。

huang@tesla:/tmp$ gcc -lssl -o test test.c
test.c: In function ‘main’:
test.c:16: warning: format ‘%d’ expects type ‘int’, but argument 2 has
type ‘size_t’
test.c:24: warning: format ‘%d’ expects type ‘int’, but argument 2 has
type ‘size_t’

huang@tesla:/tmp$ ./test
strlen key is 65
011CDED67F00154D2D3267982073896E5DE8E417BA1366B58D331DB00AD29FDB17
strlen of mod is 66

验证
Run in Common Lisp:

CL-USER> (setf x
#x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef7)
CL-USER> (write (mod (expt #x2 #x512) x) :base 16)

=> 11CDED67F00154D2D3267982073896E5DE8E417BA1366B58D331DB00AD29FDB17

--
黄 澗石 (Jianshi Huang)
http://huangjs.net/

yaoshi lee

unread,
Nov 11, 2009, 8:13:16 PM11/11/09
to sh...@googlegroups.com
有没有人知道一般这种东西,可不可以用65bit/129bit 的key ?

前面多个0的话,是掐头合适还是去尾合适?

照道理,这个0是不应该出现的哎。

2009/11/11 Jianshi Huang <jiansh...@gmail.com>

yaoshi lee

unread,
Nov 11, 2009, 8:18:53 PM11/11/09
to sh...@googlegroups.com
猛一看huang@xxxx还以为自己的机器。。。

2009/11/12 yaoshi lee <liya...@gmail.com>

Jianshi Huang

unread,
Nov 12, 2009, 12:15:55 AM11/12/09
to sh...@googlegroups.com
2009/11/12 yaoshi lee <liya...@gmail.com>:

> 有没有人知道一般这种东西,可不可以用65bit/129bit 的key ?
> 前面多个0的话,是掐头合适还是去尾合适?
> 照道理,这个0是不应该出现的哎。
>

无所谓吧,被读入后是同一个数字。

Jianshi Huang

unread,
Nov 12, 2009, 12:16:38 AM11/12/09
to sh...@googlegroups.com
2009/11/12 yaoshi lee <liya...@gmail.com>:
> 猛一看huang@xxxx还以为自己的机器。。。
>

莫非你的机器也叫 tesla?

lyxmoo

unread,
Nov 12, 2009, 1:39:08 AM11/12/09
to Shanghai Linux User Group
我进来是拜telsa的

On 11月12日, 下午1时16分, Jianshi Huang <jianshi.hu...@gmail.com> wrote:
> 2009/11/12 yaoshi lee <liyao...@gmail.com>:
>
> > 猛一看huang@xxxx还以为自己的机器。。。
>
> 莫非你的机器也叫 tesla?
>

lyxmoo

unread,
Nov 12, 2009, 2:32:36 AM11/12/09
to Shanghai Linux User Group
顺便问一句, telsa 上的cuda 和 geforce 上的开发的时候代码有区别么 ?

On 11月12日, 下午2时39分, lyxmoo <lyx...@gmail.com> wrote:
> 我进来是拜telsa的

Reply all
Reply to author
Forward
0 new messages