static int ecx_key_op(EVP_PKEY *pkey, X509_ALGOR *palg,
const unsigned char *p, int plen, ecx_key_op_t op)
{
- int ptype;
- X25519_KEY *xkey = NULL;
+ X25519_KEY *xkey;
if (op != X25519_KEYGEN) {
- /* Algorithm parameters must be absent */
- X509_ALGOR_get0(NULL, &ptype, NULL, palg);
- if (ptype != V_ASN1_UNDEF) {
- ECerr(EC_F_ECX_KEY_OP, EC_R_INVALID_ENCODING);
- return 0;
+ if (palg != NULL) {
+ int ptype;
+
+ /* Algorithm parameters must be absent */
+ X509_ALGOR_get0(NULL, &ptype, NULL, palg);
+ if (ptype != V_ASN1_UNDEF) {
+ ECerr(EC_F_ECX_KEY_OP, EC_R_INVALID_ENCODING);
+ return 0;
+ }
}
if (p == NULL || plen != X25519_KEYLEN) {
static int ecx_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
{
- return -2;
+ switch (op) {
+
+ case ASN1_PKEY_CTRL_SET1_TLS_ENCPT:
+ return ecx_key_op(pkey, NULL, arg2, arg1, X25519_PUBLIC);
+
+ case ASN1_PKEY_CTRL_GET1_TLS_ENCPT:
+ if (pkey->pkey.ptr != NULL) {
+ const X25519_KEY *xkey = pkey->pkey.ptr;
+ unsigned char **ppt = arg2;
+ *ppt = OPENSSL_memdup(xkey->pubkey, X25519_KEYLEN);
+ if (*ppt != NULL)
+ return X25519_KEYLEN;
+ }
+ return 0;
+
+ case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
+ *(int *)arg2 = NID_sha256;
+ return 2;
+
+ default:
+ return -2;
+
+ }
}
const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = {
return unsup_alg(out, pkey, indent, "Parameters");
}
-int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
+static int evp_pkey_asn1_ctrl(EVP_PKEY *pkey, int op, int arg1, void *arg2)
{
- if (!pkey->ameth || !pkey->ameth->pkey_ctrl)
+ if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL)
return -2;
- return pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID,
- 0, pnid);
+ return pkey->ameth->pkey_ctrl(pkey, op, arg1, arg2);
+}
+
+int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
+{
+ return evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, 0, pnid);
+}
+
+int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
+ const unsigned char *pt, size_t ptlen)
+{
+ if (ptlen > INT_MAX)
+ return 0;
+ if (evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_SET1_TLS_ENCPT, ptlen,
+ (void *)pt) <= 0)
+ return 0;
+ return 1;
+}
+
+size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt)
+{
+ int rv;
+ rv = evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_GET1_TLS_ENCPT, 0, ppt);
+ if (rv <= 0)
+ return 0;
+ return rv;
}
int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid);
+int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
+ const unsigned char *pt, size_t ptlen);
+size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt);
+
int EVP_CIPHER_type(const EVP_CIPHER *ctx);
/* calls methods */
# define ASN1_PKEY_CTRL_CMS_ENVELOPE 0x7
# define ASN1_PKEY_CTRL_CMS_RI_TYPE 0x8
+# define ASN1_PKEY_CTRL_SET1_TLS_ENCPT 0x9
+# define ASN1_PKEY_CTRL_GET1_TLS_ENCPT 0xa
+
int EVP_PKEY_asn1_get_count(void);
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx);
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type);