summaryrefslogtreecommitdiff
path: root/src/crypto/evp/evp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/evp/evp.c')
-rw-r--r--src/crypto/evp/evp.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/crypto/evp/evp.c b/src/crypto/evp/evp.c
index ed7cc85b..0e90b6f8 100644
--- a/src/crypto/evp/evp.c
+++ b/src/crypto/evp/evp.c
@@ -200,6 +200,8 @@ static const EVP_PKEY_ASN1_METHOD *evp_pkey_asn1_find(int nid) {
return &dsa_asn1_meth;
case EVP_PKEY_ED25519:
return &ed25519_asn1_meth;
+ case EVP_PKEY_X25519:
+ return &x25519_asn1_meth;
default:
return NULL;
}
@@ -330,7 +332,73 @@ int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) {
return 1;
}
+EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused,
+ const uint8_t *in, size_t len) {
+ EVP_PKEY *ret = EVP_PKEY_new();
+ if (ret == NULL ||
+ !EVP_PKEY_set_type(ret, type)) {
+ goto err;
+ }
+
+ if (ret->ameth->set_priv_raw == NULL) {
+ OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+ goto err;
+ }
+
+ if (!ret->ameth->set_priv_raw(ret, in, len)) {
+ goto err;
+ }
+
+ return ret;
+
+err:
+ EVP_PKEY_free(ret);
+ return NULL;
+}
+
+EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *unused,
+ const uint8_t *in, size_t len) {
+ EVP_PKEY *ret = EVP_PKEY_new();
+ if (ret == NULL ||
+ !EVP_PKEY_set_type(ret, type)) {
+ goto err;
+ }
+
+ if (ret->ameth->set_pub_raw == NULL) {
+ OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+ goto err;
+ }
+ if (!ret->ameth->set_pub_raw(ret, in, len)) {
+ goto err;
+ }
+
+ return ret;
+
+err:
+ EVP_PKEY_free(ret);
+ return NULL;
+}
+
+int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, uint8_t *out,
+ size_t *out_len) {
+ if (pkey->ameth->get_priv_raw == NULL) {
+ OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+ return 0;
+ }
+
+ return pkey->ameth->get_priv_raw(pkey, out, out_len);
+}
+
+int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, uint8_t *out,
+ size_t *out_len) {
+ if (pkey->ameth->get_pub_raw == NULL) {
+ OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
+ return 0;
+ }
+
+ return pkey->ameth->get_pub_raw(pkey, out, out_len);
+}
int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
if (a->type != b->type) {
@@ -361,3 +429,10 @@ void OpenSSL_add_all_ciphers(void) {}
void OpenSSL_add_all_digests(void) {}
void EVP_cleanup(void) {}
+
+int EVP_PKEY_base_id(const EVP_PKEY *pkey) {
+ // OpenSSL has two notions of key type because it supports multiple OIDs for
+ // the same algorithm: NID_rsa vs NID_rsaEncryption and five distinct spelling
+ // of DSA. We do not support these, so the base ID is simply the ID.
+ return EVP_PKEY_id(pkey);
+}