aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ec
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2017-04-07 01:17:40 +0100
committerDr. Stephen Henson <steve@openssl.org>2017-05-30 20:38:20 +0100
commit9f98fbad4720db05485958868363a0296cf6ec99 (patch)
treea8c7c60e5ddc968990b3dd77f55fe5d1df0bb271 /crypto/ec
parentb85236966b8518a23fe87d0d0f7c6cf435cc3878 (diff)
downloadopenssl-9f98fbad4720db05485958868363a0296cf6ec99.tar.gz
Add custom ASN.1 sign and verify
Since ED25519 doesn't have an associated digest it needs custom sign/verify routines to handle ASN.1 signatures. Reviewed-by: Rich Salz <rsalz@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3503)
Diffstat (limited to 'crypto/ec')
-rw-r--r--crypto/ec/ecx_meth.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/crypto/ec/ecx_meth.c b/crypto/ec/ecx_meth.c
index dbd53e00a7..b9046b3b87 100644
--- a/crypto/ec/ecx_meth.c
+++ b/crypto/ec/ecx_meth.c
@@ -339,6 +339,38 @@ static int ecd_size(const EVP_PKEY *pkey)
return ED25519_SIGSIZE;
}
+static int ecd_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
+ X509_ALGOR *sigalg, ASN1_BIT_STRING *str,
+ EVP_PKEY *pkey)
+{
+ const ASN1_OBJECT *obj;
+ int ptype;
+
+ X509_ALGOR_get0(&obj, &ptype, NULL, sigalg);
+ /* Sanity check: make sure it is ED25519 with absent parameters */
+ if (OBJ_obj2nid(obj) != NID_ED25519 || ptype != V_ASN1_UNDEF) {
+ ECerr(EC_F_ECD_ITEM_VERIFY, EC_R_INVALID_ENCODING);
+ return 0;
+ }
+
+ if (!EVP_DigestVerifyInit(ctx, NULL, NULL, NULL, pkey))
+ return 0;
+
+ return 2;
+}
+
+static int ecd_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
+ X509_ALGOR *alg1, X509_ALGOR *alg2,
+ ASN1_BIT_STRING *str)
+{
+ /* Set algorithms identifiers */
+ X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_ED25519), V_ASN1_UNDEF, NULL);
+ if (alg2)
+ X509_ALGOR_set0(alg2, OBJ_nid2obj(NID_ED25519), V_ASN1_UNDEF, NULL);
+ /* Algorithm idetifiers set: carry on as normal */
+ return 3;
+}
+
const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = {
NID_ED25519,
NID_ED25519,
@@ -366,7 +398,9 @@ const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = {
ecx_free,
0,
NULL,
- NULL
+ NULL,
+ ecd_item_verify,
+ ecd_item_sign
};
static int pkey_ecx_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)