-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Closed
Milestone
Description
Trying to perform a ED25519 sign/verify operation with one-shot EVP API. Since PureEdDSA does not have a digest, the type input parameter must be NULL in the EVP_DigestSignInit() API. But this results in Segmentation fault:11
Here is the specimen code:
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/err.h>
int main() {
// Generate ED25519 keypair
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, NULL);
EVP_PKEY_keygen_init(pctx);
EVP_PKEY_keygen(pctx, &pkey);
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
// type parameter must be NULL for ED25519 since it is PureEdDSA.
EVP_DigestSignInit(ctx, &pctx, NULL, NULL, pkey);
unsigned char tbs[] = "Hello world";
unsigned char sigret[256];
size_t siglen = 256;
EVP_DigestSign(ctx, sigret, &siglen, tbs, sizeof(tbs));
printf("Siglen = %d\n", (int)siglen); // expect Siglen = 64 for ED25519 signautre
// free keys and contexts
EVP_PKEY_CTX_free(pctx);
EVP_PKEY_free(pkey);
EVP_MD_CTX_free(ctx); // Seg Fault: 11 here. Changing type from NULL to non-NULL such as EVP_sha1() in EVP_DigestSignInit fixes it.
return 0;
}
Output from command line:
$ gcc main.c -I/usr/local/Cellar/openssl\@1.1/1.1.1-pre8/include -L/usr/local/Cellar/openssl\@1.1/1.1.1-pre8/lib -lcrypto
$ ./a.out
Siglen = 64
Segmentation fault: 11
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels