简体   繁体   English

使用 libgcrypt 签名,崩溃

[英]sign with libgcrypt, crashes

im trying to create a peer to peer network that is controlled by a peer with the master private key, part of that is approving peers to connect我正在尝试创建一个由具有主私钥的对等方控制的对等网络,其中一部分是批准对等方连接

the following code is suppose to take a public key, sign that and send it to the peer so that it can check if its valid and in its approved peer list以下代码假设采用公钥,对其进行签名并将其发送给对等方,以便它可以检查其是否有效并在其批准的对等方列表中

gcry_sexp_t signature, keydata;
char *blob = malloc(size + 64);

sprintf(blob, "(data\n (flags pkcs1)\n (hash sha1 #%.*s#))\n", (int)size, buf);
printf("%s\n", blob);
free(buf);

gcry_sexp_sscan(&keydata, &size, blob, strlen(blob));
printf("offset %d\n", (int)size);

size = gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, NULL, 0);
printf("size %d\n", (int)size);

buf = gcry_xmalloc(size);
gcry_sexp_sprint(keydata, GCRYSEXP_FMT_ADVANCED, buf, size);
printf("keydata: %.*s\n", size, buf);
free(buf);

gcry_pk_sign(&signature, keydata, skey);
size = gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, NULL, 0);
buf = gcry_xmalloc(size);
gcry_sexp_sprint(signature, GCRYSEXP_FMT_ADVANCED, buf, size);
//add signature buf to msg and send to peer

But it crashes.但它崩溃了。 Any ideas why?任何想法为什么?

The printf arguments are around the wrong way. printf参数是错误的。 Should be:应该:

printf("keydata: %.*s\n", size, buf);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM