17 #include <openssl/evp.h> 21 const u8 secret_key[CURVE25519_KEY_SIZE],
22 const u8 basepoint[CURVE25519_KEY_SIZE])
29 EVP_PKEY *peerkey = NULL;
31 EVP_PKEY_new_raw_private_key (EVP_PKEY_X25519, NULL, secret_key,
36 ctx = EVP_PKEY_CTX_new (pkey, NULL);
37 if (EVP_PKEY_derive_init (ctx) <= 0)
44 EVP_PKEY_new_raw_public_key (EVP_PKEY_X25519, NULL, basepoint,
46 if (EVP_PKEY_derive_set_peer (ctx, peerkey) <= 0)
53 if (EVP_PKEY_derive (ctx, shared_key, &key_len) <= 0)
59 EVP_PKEY_CTX_free (ctx);
61 EVP_PKEY_free (peerkey);
67 const u8 secret_key[CURVE25519_KEY_SIZE])
71 EVP_PKEY_new_raw_private_key (EVP_PKEY_X25519, NULL, secret_key,
74 if (!EVP_PKEY_get_raw_public_key (pkey,
public_key, &pub_len))
87 EVP_PKEY *pkey = NULL;
88 EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id (EVP_PKEY_X25519, NULL);
89 EVP_PKEY_keygen_init (pctx);
90 EVP_PKEY_keygen (pctx, &pkey);
91 EVP_PKEY_CTX_free (pctx);
94 if (!EVP_PKEY_get_raw_private_key (pkey, secret_key, &secret_len))
106 if (!EVP_EncodeBlock (out, src, src_len))
114 if (EVP_DecodeBlock (out, src, src_len - 1) <= 0)
bool key_to_base64(const u8 *src, size_t src_len, u8 *out)
bool key_from_base64(const u8 *src, size_t src_len, u8 *out)
bool curve25519_gen_secret(u8 secret_key[CURVE25519_KEY_SIZE])
bool curve25519_gen_public(u8 public_key[CURVE25519_KEY_SIZE], const u8 secret_key[CURVE25519_KEY_SIZE])
bool curve25519_gen_shared(u8 shared_key[CURVE25519_KEY_SIZE], const u8 secret_key[CURVE25519_KEY_SIZE], const u8 basepoint[CURVE25519_KEY_SIZE])