首页
社区
课程
招聘
[求助]关于libtomcrypt
发表于: 2011-4-17 21:05 8573

[求助]关于libtomcrypt

2011-4-17 21:05
8573
最近研究了下libtommath和libtomcrypt,遇到了两个问题,尝试了下,没能解决,请各位帮忙看下!
代码使用的是libtommath v0.42和 libtomcrypt v1.17,在windows xp 下使用visual studio编写。

第一个问题是关于libtommath的,如下两个程序所示,用mp_init声明变量可以正常输出结果,但是用mp_init_multi却没有任何输出。

=====================================
#include <tommath.h>
#pragma comment(lib,"tommath.h")
int main()
{
  char *str1="1234567890abcdef";
  char *str2="fedcba0987654321";
  char buf[256];
  mp_int a,b,c;
  mp_init_multi(&a,&,b,&c);
  mp_read_radix(&a,str1,16);
  mp_toradix(&a,buf,10);
  printf("a:%s\n",buf);
  mp_read_radix(&b,str2,16);
  mp_toradix(&b,buf,10);
  printf("b:%s\n",buf);
  mp_mul(&a,&b,&c);
  mp_toradix(&c,buf,10);
  printf("c:%s\n",buf);
  mp_clear_multi(&a,&b,&c);
}
==========================================
#include <tommath.h>
#pragma comment(lib,"tommath.h")
int main()
{
  char *str1="1234567890abcdef";
  char *str2="fedcba0987654321";
  char buf[256];
  mp_int a,b,c;  
  mp_init(&a);
  mp_init(&b);
  mp_init(&c);
  mp_read_radix(&a,str1,16);
  mp_toradix(&a,buf,10);
  printf("a:%s\n",buf);
  mp_read_radix(&b,str2,16);
  mp_toradix(&b,buf,10);
  printf("b:%s\n",buf);
  mp_mul(&a,&b,&c);
  mp_toradix(&c,buf,10);
  printf("c:%s\n",buf);
  mp_clear(&a);
  mp_clear(&b);
  mp_clear(&c);
}
=====================================

第二个问题,编译官方文档中第七章的示例程序,得到如下错误提示:
"LTC_ARGCHK 'ltc_mp.name != NULL' failure on line 34 of file > src/pk/ rsa/rsa_make_key.c"

=========================================
#include <tomcrypt.h>
#pragma comment(lib,"tomcrypt.lib")
int main(void)
{
  int err, hash_idx, prng_idx, res;
  unsigned long l1, l2;
  unsigned char pt[16], pt2[16], out[1024];
  rsa_key key;
  /* register prng/hash */
  if (register_prng(&sprng_desc) == -1)
  {
  printf("Error registering sprng");
  return EXIT_FAILURE;
                }
  /* register a math library (in this case TomsFastMath) */
  ltc_mp = tfm_desc;
  if (register_hash(&sha1_desc) == -1)
   {
  printf("Error registering sha1");
  return EXIT_FAILURE;
  }
  hash_idx = find_hash("sha1");
  prng_idx = find_prng("sprng");
  /* make an RSA-1024 key */
  if ((err = rsa_make_key(NULL, /* PRNG state */
        prng_idx, /* PRNG idx */
        1024/8, /* 1024-bit key */
        65537, /* we like e=65537 */
        &key) /* where to store the key */
        ) != CRYPT_OK) 
  {
  printf("rsa_make_key %s", error_to_string(err));
  return EXIT_FAILURE;
  }
  /* fill in pt[] with a key we want to send ... */
  l1 = sizeof(out);
  if ((err = rsa_encrypt_key(pt, /* data we wish to encrypt */
        16, /* data is 16 bytes long */
        out, /* where to store ciphertext */
        &l1, /* length of ciphertext */
        "TestApp", /* our lparam for this program */
        7, /* lparam is 7 bytes long */
        NULL, /* PRNG state */
        prng_idx, /* prng idx */
        hash_idx, /* hash idx */
        &key) /* our RSA key */
    ) != CRYPT_OK)
   {
  printf("rsa_encrypt_key %s", error_to_string(err));
  return EXIT_FAILURE;
  }
  /* now let’s decrypt the encrypted key */
  l2 = sizeof(pt2);
  if ((err = rsa_decrypt_key(out, /* encrypted data */
        l1, /* length of ciphertext */
        pt2, /* where to put plaintext */
        &l2, /* plaintext length */
        "TestApp", /* lparam for this program */
        7, /* lparam is 7 bytes long */
        hash_idx, /* hash idx */
        &res, /* validity of data */
        &key) /* our RSA key */
    ) != CRYPT_OK)
   {
  printf("rsa_decrypt_key %s", error_to_string(err));
  return EXIT_FAILURE;
  }
  /* if all went well pt == pt2, l2 == 16, res == 1 */
}
================================================

[课程]Android-CTF解题方法汇总!

收藏
免费 1
支持
分享
最新回复 (3)
雪    币: 433
活跃值: (45)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
上这问问
http://webchat.freenode.net/?channels=libtom

http://brlcad.org/xref/source/src/other/tcl/libtommath/
2011-4-18 15:26
0
雪    币: 157
活跃值: (10)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
加我QQ一起讨论噻~我毕设调的tom的库做的,不过是fastmath那个。。
2011-5-30 14:26
0
雪    币: 443
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
第一个问题
把mp_init_multi(&a,&,b,&c);
改成mp_init_multi(&a,&b,&c,NULL);
2011-5-31 07:51
0
游客
登录 | 注册 方可回帖
返回
//